【发布时间】:2012-07-18 21:08:07
【问题描述】:
我有两个视图,变量是从我的 TestViewController 加载的,它是一个 UITableViewController。下面是我认为有用的代码部分。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selected = [[_sectionsArray objectAtIndex:indexPath.row] objectForKey:@"Section"];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.viewController.detailSec = selected;
NSLog(@"%@",selected);
}
在我的 ViewController 中,以下代码应该将我的 UILabel 文本更改为我的变量
-(void)setDetailSec:(id)newDetailSec {
if (_detailSec != newDetailSec) {
[_detailSec release];
_detailSec = [newDetailSec retain];
[self configureView];
}
NSLog(@"Step 2 %@",_detailSec);
}
-(void)configureView {
if (self.detailSec) {
self.detailLabelChord.text = [_detailSec description];
NSLog(@"Step 3 %@", _detailSec);
}
如您所见,我添加了 NSLogs 以检查是否调用了 if 函数以及变量是否相应更改并且确实如此!但我的 UILabel 不会变!
2012-07-18 22:03:26.077 testapp[17332:11303] Step 3 CHS 21.3x3.2
2012-07-18 22:03:26.078 testapp[17332:11303] Step 2 CHS 21.3x3.2
2012-07-18 22:03:26.079 testapp[17332:11303] Step 1 CHS 21.3x3.2
有什么想法或建议吗?如果您需要更多信息,我不知道是否可以上传我的项目。
提前谢谢你
【问题讨论】:
-
你在 View Controller 的实现中 @synthesize detailLabelChord 了吗?
-
你为什么要在每次选择时添加一个新的 Viewcontroller,是不是因为它被覆盖了所以你看不到正确的 Viewcontroller?
-
您很可能会丢失对
self.detailLabelChord的引用,因为您一直在重置self.viewController。我猜self.detailLabelChord是UILabel上的ViewController笔尖? -
@Jon Friskics 是的,我已经合成它并在我的 .xib 中引用了它
-
@iOS 我应该在哪里添加我的 ViewController?如果您正在谈论“self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];”,这是我发现在 ViewController 中传输变量的唯一方法还有其他方法吗?
标签: ios xcode ipad uilabel uitableview