大佬教程收集整理的这篇文章主要介绍了iphone – 如何将数据从详细视图控制器传递回uitableview?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我能够从tableview正确导航到详细视图,但我无法在rootviewcontroller的详细视图中显示所选的项目.
请帮我解决这个问题.
图像一是我的rootview控制器页面.
例如:如果用户选择@“make”,他将能够看到@“make”的所有相关类别
.在下一页(哪个image2).
image to是我的详细页面.
当用户选择@“abarth”时,它应该显示在rootview控制器页面(第一页)中.
- (void)viewDidLoad { self.car = [[NSArray alloc]initWithObjects:@"Make",@"Model",@"Price Min",@"Price Max",@"State",nil]; [super viewDidLoad]; } -(NSInteger) numberOfSectionInTableView:(UITableView *)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.car count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath { static NSString *TextCellIdentifier = @"Cell"; UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:TextCellIdentifier]; if (cell==nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reusEIDentifier:TextCellIdentifier]; cell.accessoryType = UITableViewCellAccessoryNone; cell.SELEctionStyle = UITableViewCellSELEctionStyleNone; } cell.textLabel.text = [self.car objectATindex:[indexPath row]]; cell.accessoryType = UITableViewCellAccessoryDisclosureInDicator; return cell; } - (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath { if (0 == indexPath.row) { NSLog(@"0"); self.detailcontroller.title = @"Make"; } else if (1 == indexPath.row) { NSLog(@"1"); self.detailcontroller.title = @"Model"; } else if (2 == indexPath.row) { NSLog(@"2"); self.detailcontroller.title = @"Price Min"; } else if (3 == indexPath.row) { self.detailcontroller.title = @"Price Max"; } else if (4 == indexPath.row) { NSLog(@"3"); self.detailcontroller.title = @"State"; } [self.navigationController pushViewController:self.detailcontroller animated:YES]; } following is my detail view page code: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if ([self.title isEqualToString:@"Make"]) { detail = [[NSArray alloc]initWithObjects:@"Any Make",@"Abarth",@"AC",@"ADAYER",@"Adelaide",@"ALFA ROMEO",@"ALLARD",@"ALPINE-RENAULT",@"ALVIS",@"ARMSTRONG",@"ASTON MARTin",@"AUDI",@"AUSTin",@"AUSTin HEALEY",@"Barossa",@"BEDFORD",@"BENTLEY",@"BERTONE",@"BMW",@"BOLWELL",@"BRISTOL",@"BUICK",@"BULLET",@"CADILLAC",@"CATERHAM",@"CHERY",@"CHEVROLET",@"CHRYSLER",@"CITROEN",@"Country Central",@"CSV",@"CUSTOM",@"DAEWOO",@"DAIHATSU",@"DAIMLER",@"DATSUN",@"DE TOMASO",@"DELOREAN",@"DODGE",@"ELFIN",@"ESSEX",@"EUNOS",@"EXCALIBUR",@"FERRARI",nil]; if ([self.title isEqualToString:@"Abarth"]) { detail = [[NSArray alloc]initWithObjects:@"HI",nil]; } } else if ([self.title isEqualToString:@"Model"]) { detail = [[NSArray alloc]initWithObjects:@"Any Model",nil]; } else if ([self.title isEqualToString:@"Price Min"]) { detail = [[NSArray alloc]initWithObjects:@"Min",@"$2,500",@"$5,000",@"$7,@"$10,@"$15,@"$20,@"$25,@"$30,@"$35,@"$40,@"$45,@"$50,@"$60,@"$70,@"$80,@"$90,@"$100,@"$500,@"$1,000,nil]; } else if ([self.title isEqualToString:@"Price Max"]) { detail = [[NSArray alloc]initWithObjects:@"Max",nil]; } else if ([self.title isEqualToString:@"State"]) { detail = [[NSArray alloc]initWithObjects:@"Any State",@"Australian Capital Territory",@"New South Wales",@"Northern Territory",@"Queensland",@"South Australia",@"Tasmania",@"Victoria",@"Western Australia",nil]; } [self.tableView reloadData]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [detail count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:CellIdentifier]; } cell.textLabel.text = [detail objectATindex: [indexPath row]]; cell.font = [UIFont systemFontOfSize:14.0]; return cell; } - (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath { [self.navigationController popViewControllerAnimated:YES]; }@H_419_27@
//something like this @interface detailViewController // protocol declaration @protocol myDelegate @optional -(void)SELEctedValueIs:(NSString *)value; // set it as the property @property (nonatomic,assign) id<myDelegate> SELEctedValueDelegate; // in your implementation class synthesize it and call the delegate method @implementation detailViewController @synthesize SELEctedValueDelegate // in your didSELEctRowATindex method call this delegate method - (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath { [self SELEctedValueDelegate])SELEctedValueIs:valueString] ; [self.navigationController popViewControllerAnimated:YES]; } @end // In your rootViewController conform to this protocol and then set the delegate detailViewCtrlObj.SELEctedValueDelegate=self; //Implement the delegate Method -(void)SELEctedValueIs:(NSString *)value{ { // do whatever you want with the value String }@H_419_27@
以上是大佬教程为你收集整理的iphone – 如何将数据从详细视图控制器传递回uitableview?全部内容,希望文章能够帮你解决iphone – 如何将数据从详细视图控制器传递回uitableview?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。