我正在开发一个应用程序,其中有三个不同的表格和一个包含标签的 UiView。我想显示所选表格 View 单元格名称的名称,将其设置为标签。
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate * appdelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
if(appdelegate.btn1)
{
appdelegate.selectId=indexPath.row;
NSLog(@"select Id %d",appdelegate.selectId);
}
else if(appdelegate.btn2)
{
appdelegate.selectId=indexPath.row;
NSLog(@"select Id %d",appdelegate.selectId);
}
else if(appdelegate.btn3)
{
appdelegate.selectId=indexPath.row;
NSLog(@"select Id %d",appdelegate.selectId);
}
NSString * str=[appdelegate.name objectAtIndex:indexPath.row];
NSString * str1=[appdelegate.iname objectAtIndex:indexPath.row];
NSString * str2=[appdelegate.bname objectAtIndex:indexPath.row];
DetailViewController * dvc=[[DetailViewController alloc]initWithTrick:str andOtherString:str1 andOtherString:str2];
[self.navigationController pushViewController:dvc animated:YES];
}
并在 init 方法中访问该单元格名称。
-(id)initWithTrick:(NSString *)name_ andOtherString:(NSString *)name2_ andOtherString:(NSString *)name3_;
{
if (self)
{
self.trickname=name_;
self.trickname2=name2_;
self.trickname3=name3_;
}
return self;
}
这里trickname,trickname2,trickname3是NSString。
我已经尝试过这段代码,但对我不起作用。
请帮我解决这个问题。
最佳答案
-(id)initWithTrick:(NSString *)name_ andOtherString:(NSString *)name2_ andOtherString:(NSString *)name3_;
{
self =[super init];
if (self)
{
self.trickname=name_;
self.trickname2=name2_;
self.trickname3=name3_;
}
return self;
}
试试这个可能会对你有帮助。您的 self 对象未初始化,因此未在字符串中设置值。
关于ios - 将多个值传递给 nextview Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16370938/