그래서 두 개의보기간에 데이터를 전달하려고합니다. 첫 번째보기는 셀을 눌렀을 때 두 번째보기로 보내고 두 번째보기는 imageView가 있고 데이터가 이미지를 보내는 경우 표시됩니다. 자습서 iphonedevsdk.보기간에 데이터 전달
- (AppDataObject*) theAppDataObject
{
id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication sharedApplication].delegate;
AppDataObject* theDataObject;
theDataObject = (AppDataObject*) theDelegate.theAppDataObject;
return theDataObject;
}
셀은 내가 데이터 theAppDataObject.imageString = tempImageString;
보내려고 누르면 :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
tempImageString = (((championList *) [self.champions objectAtIndex:indexPath.row]).championImage);
AppDataObject *theDataObject = [self theAppDataObject];
NSLog(@"tempIm-g = %@",tempImageString);
theDataObject.imageString = tempImageString;
NSLog(@"theAppDataObject.imageString = %@",theDataObject.imageString);
[self.navigationController popToRootViewControllerAnimated:YES];
}
NSLog 출력을 :
내보기에 같은 theAppDataObject 방법을 사용하고
tempIm-g = Champ_0.jpg
theAppDataObject.imageString = (NULL)
SecondViewController (표시 화상) :
-(void)viewWillAppear:(BOOL)animated
{
AppDataObject* theDataObject = [self theAppDataObject];
UIImage *tempImage = [UIImage imageNamed:theDataObject.imageString];
NSLog(@"temp image = %@",tempImage);
[choosenChampionImageView setImage:tempImage];
}
NSLog 출력 :
임시 화상 = (NULL)
내 문제 theAppDataObject.imageString은 항상 null입니다.
내가 아는가능한 해결책 :
는 일반 데이터 컨테이너로 AppDataObject를 사용하고 단지 AppDelegate에 데이터를 저장하지 마십시오.
예는 :
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
appdelegate.imageString = tempImageString;
는하지만 난 프로토콜을 사용하는 방법을 알아 내려고합니다.
내가 뭘하려 : 이 theDataObject 글로벌하십시오 :
view1.h
@interface championsListTableViewController : UITableViewController
{
NSString *tempImageString;
AppDataObject* theDataObject;
}
@property(strong,nonatomic) NSString *tempImageString;
@property(strong,nonatomic) AppDataObject* theDataObject;
출력을 NSLog의 (@는 theDataObject "theDataObject는 %의 @입니다"); :
theDataObject는 (null)입니다. 어떻게 가능합니까?
당신이 내 대답을 확인 했습니까? 'AppDataObject * theDataObject;'는 코드에서 지역적인 문제입니다. 인터페이스에 쓰기 –
DataObject의 로컬 선언을 제거 했습니까? –
네, 그것을 제거했습니다 – ignotusverum