小编Aru*_*run的帖子

IOS 7 - 如何从放置在UITableViewCell中的按钮获取indexPath

我以编程方式创建了一个UITableView,并将UISwitch添加到它的单元附件视图中.

这是我在cellForRowAtIndexPath方法中的单元附件视图中的UISwitch代码.

UISwitch *accessorySwitch = [[UISwitch alloc]initWithFrame:CGRectZero];
[accessorySwitch setOn:NO animated:YES];
[accessorySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = accessorySwitch;
Run Code Online (Sandbox Code Playgroud)

这是单击按钮后调用的方法.

- (void)changeSwitch:(UISwitch *)sender{

    UITableViewCell *cell = (UITableViewCell *)[sender superview];

    NSIndexPath *indexPath = [self.filterTableView indexPathForCell:cell];
    NSLog(@"%ld",(long)indexPath);

 ……………. My other code…….
}
Run Code Online (Sandbox Code Playgroud)

我能够在iOS 6中打印索引路径值但是在iOS 7中它打印为nil,

我在iOS 7中遗漏了什么,或者在iOS 7中有其他方法来获取indexPath

谢谢,阿伦.

iphone uitableview ios ios7

29
推荐指数
3
解决办法
3万
查看次数

在iPad中,UIImagePickerController必须通过UIPopoverController呈现

我已经从相机创建了一个捕获图像的应用程序.这是我的代码

 -(IBAction) showCameraUI {
    BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    UIImagePickerController* picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera :    UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

并实现了这种委托方法来获取捕获的图像

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissModalViewControllerAnimated:YES];
    UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImage *yourImageView = image;
}
Run Code Online (Sandbox Code Playgroud)

如果用户取消控制器,则实现此方法

- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
    [picker dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)

但它显示了这个例外.有没有人知道为什么它在执行函数showCameraUI的最后一行后显示这样的异常.

UIStatusBarStyleBlackTranslucent is not available on this device. 2013-02-07 
10:06:06.976 CaptureImage[460:c07] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ipad ios ios6

11
推荐指数
2
解决办法
9443
查看次数

标签 统计

ios ×2

iphone ×2

ios6 ×1

ios7 ×1

ipad ×1

objective-c ×1

uitableview ×1