我想在我的新视图(我在选择表行上加载)上设置标签为变量NSString值, 这就是我在做什么
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int selected_row = [indexPath row];
SingleTon *index_instance = [SingleTon sharedInstanceIndex];
[index_instance setIndex:selected_row];
selected_row = [index_instance getIndex:selected_row];
NSLog(@"Selected row %d", selected_row);
[SelecetionViewController uploadthecontent:selected_row];
[self presentModalViewController:selection_controller animated:YES];
}
.h文件包含
NSString *rest_name;
IBOutlet UILabel *lbl;
//Some class methods declared
.m文件包含
- (void)viewDidLoad {
[super viewDidLoad];
lbl.text = rest_name;
}
//class method
+ (void)uploadthecontent:(int)data
{
SelecetionViewController *controller = [[SelecetionViewController alloc] init];
[controller labelset:data]; //calls labelset method which set rest_name to some value
[controller release];
}
-(void)labelset:(int)data{
[rest_name release];
SingleTon *indexinstance = [SingleTon sharedInstanceIndex];
SingleTon *rnameinstace = [SingleTon sharedInstance1];
//SingleTon *baddrinstance = [SingleTon sharedInstance2];
NSMutableArray *selected_rname;
//eNSMutableArray *selected_baddr;
int i = [indexinstance getIndex:data];
selected_rname = [rnameinstace getRName:selected_rname];
NSString * rname = [[NSArray arrayWithArray:selected_rname] objectAtIndex:i];
NSLog(@"Retaurant name : %@",rname);
//lbl.text = rest_name;
rest_name = [[NSString alloc] init];
rest_name = rname;
NSLog(@"I am here : %@",rest_name);
//[rest_name retain];
}
//rest_name is what I am trying to access and set as label
答案 0 :(得分:0)
听起来你的插座可能没有连接?
答案 1 :(得分:0)
您可能无法在Interface Builder中连接lbl
Oulet。在界面构建器中选择View Controller,查看connections部分并将lbl
连接到View中的UILabel
对象。
答案 2 :(得分:0)
这个问题已经超过一年了,但是因为我在寻找解决方案的过程中发现它,我想我可能会回答它。至少是我的问题。
我只是有完全相同的行为。我犯的错误是我忘记将我创建的Outlets(UITextFields)连接到Interface Builder中的文件所有者。