UitableViewCell에서 Uibutton의 문제
-
11-09-2019 - |
문제
내 응용 프로그램에서는 사용자 정의 테이블을 사용하고 있습니다. 각 셀에는 uibutton과 uiimage가 있습니다. 버튼에서 터치 업이 발생하면 uiimagepickercontroller 메소드를 호출하여 iPhone 라이브러리에서 사진을 선택하고 이미지보기에 표시하고 싶습니다. 나는 그것을 썼다. 그러나 경고를 얻는다 ... 'CustomCell'은 presentModalViewController 애니메이션에 응답하지 않을 수 있습니다 ... 여기서 CustomCell은 내 메인 클래스 MyApp의 서브 클래스, 또한 커스텀 셀의 펜촉의 이름입니다. 누구든지 문제를 알고 있습니까 ???? 감사...
편집하다
- (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이 View Controller에 대한 포인터를 제공 한 다음 전화 할 수 있습니다. -presentModelViewController:animated:
보기 컨트롤러에서.
사용자 정의 셀 클래스에 인스턴스 변수를 추가하십시오.
@interface CustomCell : UITableViewCell {
UIViewController *viewController;
}
@property (nonatomic, assign) UIViewController *viewController;
@end
~ 안에 -tableView:cellForRowAtIndexPath:
, 새 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;
}
}
}
그런 다음 CustomCell 클래스에서 교체하십시오
[self presentModalViewController:picker animated:YES];
~와 함께
[self.viewController presentModalViewController:picker animated:YES];
다른 팁
이것은 당신의 질문에 답하지 않지만, 당신이 UIButton
셀에서는 아마도 UI 디자인을 잘못하고있을 것입니다. 전체 셀이 동작을 수행하도록하는 방법을 생각하십시오. 그렇지 않은 경우 공개 가제트 또는 무언가를 사용하십시오.