Iphone UItableViewCell中的uibutton出现问题
在我的应用程序中,我使用的是定制表。每个单元格都有一个uibutton和uiimage。当触碰按钮时,我想调用uiimagepickercontroller方法从iphone库中选择一张图片并在图像视图中显示。我已经写好了,但是得到了一个警告……”customCell'可能不响应当前ModalViewController动画。。。这里customCell是我的主类myApp的子类,也是自定义单元格的nib的名称。有人知道这个问题吗???? 谢谢 编辑Iphone UItableViewCell中的uibutton出现问题,iphone,uitableview,uiimagepickercontroller,Iphone,Uitableview,Uiimagepickercontroller,在我的应用程序中,我使用的是定制表。每个单元格都有一个uibutton和uiimage。当触碰按钮时,我想调用uiimagepickercontroller方法从iphone库中选择一张图片并在图像视图中显示。我已经写好了,但是得到了一个警告……”customCell'可能不响应当前ModalViewController动画。。。这里customCell是我的主类myApp的子类,也是自定义单元格的nib的名称。有人知道这个问题吗???? 谢谢 编辑 - (IBAction)selectExis
- (IBAction)selectExistingPicture1 {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
CGSize newSize = CGSizeMake(80, 80);
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView.image = newImage;
[picker dismissModalViewControllerAnimated:YES]; //warning shown here
}
这是自定义单元格类。。并且viewController类具有
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
for (id currentObject in nib){
if ([currentObject isKindOfClass:[CustomCell class]]){
cell = (CustomCell *)currentObject; break;
}
}
}
NSUInteger s= indexPath.section;
//[cell setText:[NSString stringWithFormat:@"I am cell %d", indexPath.row]];
NSUInteger r = indexPath.row;
cell.imageView.image = nil;
for (s;s==0;s++)
for(r;r==0;r++)
{
UIImage *img=imageView.image;
cell.imageView.image = img;
}
return cell;
}
UITableViewCell
不响应-presentModalViewController:animated:
您可能会给CustomCell一个指向视图控制器的指针,然后在视图控制器上调用-presentModelViewController:animated:
将实例变量添加到自定义单元格类:
@interface CustomCell : UITableViewCell {
UIViewController *viewController;
}
@property (nonatomic, assign) UIViewController *viewController;
@end
在-tableView:cellforrowatinexpath:
中,创建新的CustomCell后,设置属性:
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
for (id currentObject in nib){
if ([currentObject isKindOfClass:[CustomCell class]]){
cell = (CustomCell *)currentObject;
cell.viewController = self; // <-- add this
break;
}
}
}
与
这不会回答你的问题,但是如果你必须在单元格中有一个
UIButton
,那么你的UI设计可能会出错。试着想出一种方法让整个单元格执行该操作,如果不是这样的话,使用一个公开小工具或其他东西。我已经用单元格中的uibutton完成了。。将图像从库导入到每个单元格的图像视图。但新的问题是,它们在向下滚动表格时消失了……我是否必须更改CellForRowatineXpath:method中的任何内容??
[self presentModalViewController:picker animated:YES];
[self.viewController presentModalViewController:picker animated:YES];