如何检查文件目录中Swift是否存在文件?
我正在使用[ .writeFilePath ]方法将图像保存到Documents目录中,我想在每次启动应用程序时加载它.但是如果没有保存的图像,我有一个默认图像.
但我无法理解如何使用该[ func fileExistsAtPath(_:) ]功能.有人可以给出一个使用函数的示例,并将路径参数传递给它.
我相信我不需要在那里粘贴任何代码,因为这是一个通用的问题.任何帮助都感激不尽.
干杯
我有一个UIImageView有一些固定的矩形.但我的图像尺寸不固定.我想根据UIImageView的rect大小显示图像.无论图像的分辨率是大还是大,它都必须根据UIImageView的大小固定显示.我很困惑使用以下资产.
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw
Run Code Online (Sandbox Code Playgroud)
在autoresize mask中设置什么?他们的表现如何?
此代码适用于iOS5/iOS6但不适用于iOS7.
CFErrorRef *error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
//ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);
for(int i = 0; i < numberOfPeople; i++) {
ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
// NSLog(@"Name:%@ %@", firstName, lastName);
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *phoneNumber;
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
phoneNumber = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, …Run Code Online (Sandbox Code Playgroud) 我正在从库中选择视频剪辑.我想创建它的缩略图.我已应用此代码.但图像出现了旋转.我想要它的原始视图.
- (UIImage*)testGenerateThumbNailDataWithVideo {
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:appDelegate.videoURL options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = NULL;
CMTime time = CMTimeMake(1, 60);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
[generate release];
NSLog(@"err==%@, imageRef==%@", err, imgRef);
UIImage *currentImg = [[[UIImage alloc] initWithCGImage:imgRef] autorelease];
static BOOL flag = YES;
if (flag) {
NSData *tmpData = UIImageJPEGRepresentation(currentImg, 0.8);
NSString *path = [NSString stringWithFormat:@"%@thumbNail.png", NSTemporaryDirectory()];
BOOL ret = [tmpData writeToFile:path atomically:YES];
NSLog(@"write to path=%@, flag=%d", path, ret);
flag = NO; …Run Code Online (Sandbox Code Playgroud) 我想标记我UINavigationController的动画(推/弹)或不是.
我有一个BOOL变量(_isAnimating),下面的代码似乎工作:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
_isAnimating = YES;
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
_isAnimating = NO;
}
Run Code Online (Sandbox Code Playgroud)
但它在iOS7中使用滑动手势无法正常工作.假设我的导航是:root-> view A - > view B. 我现在在B.
在滑动开始时(从B回到A)navigationController:willShowViewController:animated:(BOOL)animated,然后调用函数" " _isAnimating = YES.
正常情况是滑动完成(返回A)navigationController:didShowViewController:animated:(BOOL)animated,然后调用函数" " _isAnimating = NO.这种情况没问题,但是:
如果用户可能只刷一半(半转换到A),然后不想滑动到上一个视图(视图A),他再次转到当前视图(再次保持B).然后navigationController:didShowViewController:animated:(BOOL)animated没有调用函数" ",我的变量值不正确(_isAnimating=YES).
在这种异常情况下,我没有机会更新我的变量.有没有办法更新导航状态?谢谢!
我的facebook api名称包含感叹号(!).每当我通过API在Facebook上分享内容时,帖子都包含API名称,但它会删除感叹号.有没有人知道如何显示!.
编辑1:请看下面的图片,以更好地了解我的问题.

我观察了iOS 10.2.1设备和iOS 10.3 beta 3设备中应用程序的行为https://developer.apple.com/library/content/samplecode/GenericKeychain/Introduction/Intro.html
iOS 10.3 beta 3中正在删除Keychain数据.这在早期版本中仍然存在.
我们有替代方法吗?
我的一个奇怪的问题UITableView.每当我按下我的第一行时UITableView,该didDeselectRowAtIndexPath方法都不会被调用.我目前的代码如下.
# pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.ary_tblDisplay count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 80;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TableCell";
UIView *colorView,*backgroundView;
UILabel *lblCode,*lblStatus,*lblDate;
UITableViewCell *cell = (UITableViewCell *) [self.tbl_claims dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
colorView = [[UIView alloc] initWithFrame:CGRectMake(7, 5, 5, 70)];
[cell addSubview:colorView]; …Run Code Online (Sandbox Code Playgroud) 我有UITabBarController有4个选项卡.我在UITabBarController的每个选项卡上都有4个视图.每当我单击UITabBarController的第三个选项卡时,我想更改UITabBarController的第二个选项卡的UIViewController.
第一个截图是iOS7,不是我想要的.
第一个截图是iOS6,我想要的.
Tableview的风格很简单.
Tableview的分隔符是none.
还有一个深灰色的背景视图.
我有如下代码
if ([tableView respondsToSelector:@selector(setSeparatorInset:)])
{
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"icon_bg_box.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
Run Code Online (Sandbox Code Playgroud)


我正在为我的应用程序需求工作日历功能.我今天点击日期或明天日期或其他日期需要显示吉祥的详细信息.UITextview我一直在尝试在文本视图中格式化字符串,但我无法解决它.我是xcode的新手HTML.我想删除我的stringResonse 中的标签并显示在UITextview.
我在我的代码中这样写:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
if(connection==urlConnection)
{
NSString *strResponse=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"String Response is : %@",strResponse);
NSMutableString *mutString=[NSMutableString string];
NSString *s=nil;
NSString *s1=nil;
//NSArray *arr1=[strResponse componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<br>"]];
NSArray *arr2=[strResponse componentsSeparatedByString:@"\n"];
NSLog(@"array %@",arr2);
for(s in arr2)
{
s = [s stringByReplacingOccurrencesOfString: @"<br>" withString: @"\n"];
s1=[s stringByReplacingOccurrencesOfString:@"<font color>" withString:@" "];
[mutString appendString:@""];
[mutString appendString:s1];
}
text1.text=[text1.text stringByAppendingString:mutString];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. …Run Code Online (Sandbox Code Playgroud) ios ×9
iphone ×7
objective-c ×4
ios7 ×3
ipad ×3
uitableview ×2
cocoa-touch ×1
facebook ×1
ios10 ×1
ios10.3 ×1
keychain ×1
swift ×1
swipe ×1
thumbnails ×1
uiimageview ×1
xcode ×1