本文将带您了解关于ios–目标C–何时使用NSNumber与基元的新内容,同时我们还将为您解释c语言目标未创建是什么意思?的相关知识,另外,我们还将为您提供关于ios–从视频中检索缩略图–目标C.、i
本文将带您了解关于ios – 目标C – 何时使用NSNumber与基元的新内容,同时我们还将为您解释c语言目标未创建是什么意思?的相关知识,另外,我们还将为您提供关于ios – 从视频中检索缩略图 – 目标C.、ios – 内部循环如何工作 – 目标C – 基础、ios – 如何在Facebook墙上分享文字和图像(目标C)、ios – 如何在tableview中显示联系人 – 目标C.的实用信息。
本文目录一览:- ios – 目标C – 何时使用NSNumber与基元(c语言目标未创建是什么意思?)
- ios – 从视频中检索缩略图 – 目标C.
- ios – 内部循环如何工作 – 目标C – 基础
- ios – 如何在Facebook墙上分享文字和图像(目标C)
- ios – 如何在tableview中显示联系人 – 目标C.
ios – 目标C – 何时使用NSNumber与基元(c语言目标未创建是什么意思?)
我知道应该使用原始数据类型进行计算,所以你要说[NSNumber numberWithInteger:myInt].但是,如果90%的时间只需要基本数据类型,那么另外10%是否有理由创建NSNumber并且不断使用[NSNumber intValue]来检索原语?尽可能长时间地坚持原语或者NSNumber的OO优势是否超过那些?
作为Objective C的新手,我也很好奇最佳实践是什么 – 来自Ruby和PHP等语言不会发生这种情况.
解决方法
NSNumber最常见的用途是将它放入NSArray,NSDictionary或序列化它(例如进入NSUserDefaults).大多数情况下,数字只是某个其他对象的属性,作为NSInteger.
ios – 从视频中检索缩略图 – 目标C.
我有以下代码用于从服务器获取视频并播放它:
- (void)openVideo { Nsstring *videoURLString = @"http://myite.com/dev/iphone/uploads/t69566.mov"; NSURL *videoURL = [NSURL URLWithString:videoURLString]; MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease]; [self presentMoviePlayerViewControllerAnimated:moviePlayerView]; }
现在很粗糙,我很想让openVideo与视频帖子一起动态,但我仍然坚持使用这个视频并抓取一个框架或缩略图并显示它.
建议?想法?
更新:
我想从服务器拍摄的视频中获取缩略图.这实际上给我带来了一个问题.
当用户首次上传视频时,最好只在那里创建一个缩略图并将其上传到我的服务器,并将其与视频相关联,抓住它们以填充新闻Feed类型?
解决方法
> _thumbnailView是一个显示缩略图的UIImageView.
> _activityView是一个UIActivityIndicatorView,在缩略图完成加载时会被隐藏.
AVPlayerItem *playerItem = [[AVPlayerItem playerItemWithURL:movieURL] retain]; AVAssetimageGenerator *_generator; _generator = [[AVAssetimageGenerator assetimageGeneratorWithAsset:playerItem.asset] retain]; [playerItem release]; AVAssetimageGeneratorCompletionHandler handler = ^(CMTime requestedTime,CGImageRef image,CMTime actualTime,AVAssetimageGeneratorResult result,NSError *error) { if (result == AVAssetimageGeneratorSucceeded) { UIImage *thumb = [UIImage imageWithCGImage:image]; [_thumbnailView setimage:thumb forState:UIControlStatenormal]; } else { DLog(@"%s - error: %@",__PRETTY_FUNCTION__,error); } dispatch_async(dispatch_get_main_queue(),^{ _thumbnailView.hidden = NO; _playButton.hidden = NO; [_activityView stopAnimating]; }); }; [_generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:CMTimeMakeWithSeconds(30,30)]] completionHandler:handler];
回到你的问题,在我看来,服务器端生成的缩略图通常更好,因为服务器具有更强的处理能力.此外,为了获得此缩略图,您需要开始从服务器下载实际视频.
最后,不是你传递CMTime参数,包括对CMTimeMakeWithSeconds()的调用.这可能会有问题,因为您可以轻松打出空白帧.这就是我们使用30作为参数的原因,因此我们在视频中避免这种情况.
ios – 内部循环如何工作 – 目标C – 基础
https://stackoverflow.com/a/5163334/1364174
其中介绍了如何实现in循环.
NSFastEnumerationState __enumState = {0}; id __objects[MAX_STACKBUFF_SIZE]; NSUInteger __count; while ((__count = [myArray countByEnumeratingWithState:&__enumState objects:__objects count:MAX_STACKBUFF_SIZE]) > 0) { for (NSUInteger i = 0; i < __count; i++) { id obj = __objects[i]; [obj doSomething]; } }
问题是,我发现它错了.
首先,当您启用自动引用计数(ARC)时,您会收到错误消息
将’__strong id *’发送到’__unsafe_unretained_id *’类型的参数会更改指针的保留/释放属性
但即使我关闭ARC,我发现__object数组似乎表现得很奇怪:
这是实际代码(我假设MAX_STACKBUFF_SIZE为40):
@autoreleasepool { NSArray *myArray = @[@"a",@"b",@"c",@"d",@"e",@"f",@"g"]; int MAX_STACKBUFF_SIZE = 40; NSFastEnumerationState __enumState = {0}; id __objects[MAX_STACKBUFF_SIZE]; NSUInteger __count; while ((__count = [myArray countByEnumeratingWithState:&__enumState objects:__objects count:MAX_STACKBUFF_SIZE]) > 0) { for (NSUInteger i = 0; i < __count; i++) { id obj = __objects[i]; __enumState.itemsPtr NSLog(@" Object from __objects ! %@",obj); // on screenshot different message } } } return 0;
当我尝试获取__object数组的内容时,我得到了EXC_BAD_ACESS.
我还发现当你尝试迭代__enumState.itemsPtr它实际上是有效的.
你能解释一下这里发生了什么吗?为什么我的__objects似乎“萎缩”了.为什么它不包含所需的对象?当ARC打开时,为什么会出现这种错误.
非常感谢您提前花时间和精力! (我提供了截图,以便更好地了解导致错误的原因)
解决方法
如
__unsafe_unretained id __objects[MAX_STACKBUFF_SIZE];
如果你用ARC编译.
现在,从NSFastEnumeration文档中(对我来说)并不明显,但确实如此
在Cocoa With Love:Implementing countByEnumeratingWithState:objects:count:解释
实现不需要填充提供的对象数组,但可以设置
__enumState.itemsPtr到现有数组(例如一些内部存储).在那种情况下,内容
__objects数组未定义,导致崩溃.
更换
id obj = __objects[i];
通过
id obj = __enumState.itemsPtr[i];
给出预期的结果,这是你观察到的.
另一个参考资料可以在“FastEnumerationSample”示例代码中找到:
You have two choices when implementing this method:
1) Use the stack
based array provided by stackbuf. If you do this,then you must
respect the value of ‘len’.2) Return your own array of objects. If
you do this,return the full length of the array returned until you
run out of objects,then return 0. For example,a linked-array
implementation may return each array in order until you iterate
through all arrays.In either case,
state->itemsPtr
MUST be a valid array (non-nil). …
ios – 如何在Facebook墙上分享文字和图像(目标C)
我想知道如何分享作者姓名,书名和图像(第2张表格详情).
我正在展示那样做的代码..
因此,当用户想要分享细节时,他将不得不点击作者UITableView的每个单元格中的UIButton.
didselectatindexpath NSDictionary *selectedAuthor = nil; NSArray *sectionArray=[mainIndexDictionary objectForKey:[allKeysArray objectAtIndex:indexPath.section]]; selectedAuthor = [sectionArray objectAtIndex:indexPath.row]; iPath=[[selectedAuthor objectForKey:@"SymptIndexID"] intValue]; NSLog(@"iPath - %d",iPath); authortitleString=[[selectedAuthor objectForKey:@"authorIndexName"]stringByAppendingString:@" cure!"]; } bookArray=[objDB customCellData:(NSInteger)iPath]; [self.view bringSubviewToFront:authorView]; [bookTableView scrollRectToVisible:CGRectMake(0.0,0.0,320.0,10.0) animated:NO]; [bookTableView reloadData] ;
解决方法
你可以实现如下(你必须将 social framework添加到你的项目)
#import <Social/Social.h> - (void)ShareFacebook { SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){ [fbController dismissViewControllerAnimated:YES completion:nil]; switch(result){ case SLComposeViewControllerResultCancelled: default: { NSLog(@"Cancelled....."); // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]]; } break; case SLComposeViewControllerResultDone: { NSLog(@"Posted...."); } break; }}; [fbController setinitialText:@"This is My Sample Text"]; [fbController setCompletionHandler:completionHandler]; [self presentViewController:fbController animated:YES completion:nil]; } else{ UIAlertView *alert = [[[UIAlertView alloc]initWithTitle:@"Sign in!" message:@"Please first Sign In!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil,nil]autorelease]; [alert show]; } }
ios – 如何在tableview中显示联系人 – 目标C.
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [self getPersonOutOfAddressBook]; [super viewDidLoad]; // Do any additional setup after loading the view,typically from a nib. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.tableData count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static Nsstring *cellIdentifier = @"Identifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } Person *person = [self.tableData objectAtIndex:indexPath.row]; cell.textLabel.text = person.fullName; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (void)getPersonOutOfAddressBook { //1 CFErrorRef error = NULL; ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL,&error); __block BOOL accessGranted = NO; if (ABAddressBookRequestAccessWithCompletion != NULL) { // We are on iOS 6 dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); ABAddressBookRequestAccessWithCompletion(addressBook,^(bool granted,CFErrorRef error) { accessGranted = granted; dispatch_semaphore_signal(semaphore); }); } if (addressBook != nil) { NSLog(@"Succesful."); //2 NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookcopyArrayOfAllPeople(addressBook); //3 NSUInteger i = 0; for (i = 0; i < [allContacts count]; i++) { Person *person = [[Person alloc] init]; ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i]; //4 Nsstring *firstName = (__bridge_transfer Nsstring *)ABRecordcopyValue(contactPerson,kABPersonFirstNameProperty); Nsstring *lastName = (__bridge_transfer Nsstring *)ABRecordcopyValue(contactPerson,kABPersonLastNameProperty); Nsstring *fullName = [Nsstring stringWithFormat:@"%@ %@",firstName,lastName]; person.firstName = firstName; person.lastName = lastName; person.fullName = fullName; [self.tableData addobject:person]; } //8 CFRelease(addressBook); } else { //9 NSLog(@"Error reading Address Book"); } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // dispose of any resources that can be recreated. } @end
当我使用调试器时,它显示变量firstname,lastname和fullname可以访问adressbook,因为我可以看到person的名字或姓氏.但我认为添加到数组有问题因为我在这个数组中看不到任何东西.有人能帮助我吗?我是Objective-C的初学者所以请忍耐:)
解决方法
self.tableData = [[NSMutableArray alloc] init];
关于ios – 目标C – 何时使用NSNumber与基元和c语言目标未创建是什么意思?的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于ios – 从视频中检索缩略图 – 目标C.、ios – 内部循环如何工作 – 目标C – 基础、ios – 如何在Facebook墙上分享文字和图像(目标C)、ios – 如何在tableview中显示联系人 – 目标C.的相关知识,请在本站寻找。
本文标签: