初始化 NSMutableArray
我对 xcode 3 非常陌生,我确实需要帮助,
我使用 UITableView 和 XML 开发了我的应用程序来显示内容。
我有 3 个 .xib 文件,分别是 rootViewController 、 SecondViewController 和 mainview 。
所以问题是: 当我尝试在 rootViewController 中执行 didSelectrow 并访问 SecondViewController 中的 NSMutableArray *array 并在推送动画之前将 *array 值替换为 rootViewController 中的新数组值。
我的 SecondViewController 上的数组值第一次更改,但是当我按下后退按钮并选择另一行时,我的 SecondViewController 数组继续读取前一个数组,而不更改为新数组。我尝试初始化但没有运气
这是我在 rootViewController UITableview (didSelectRow) 上的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(2ndController == nil)
2ndController = [[DetailViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
//Declare xml NSMutable array record
ListRecord *record = [self.entries objectAtIndex:indexPath.row];
//access SecondViewController NSMutable *record
2ndController.record = [[[NSMutableArray alloc] init] autorelease];
//inserting the value from firstview to secondview before push
2ndController.record = record;
//push animation
[self.navigationController pushViewController:2ndController animated:YES];
}
这是我的第二个视图控制器:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch(indexPath.section)
{
case 0:
[cell setText:record.name];
break;
case 1:
[cell setText:record.Age];
break;
case 2:
[cell setText:record.summary];
break;
}
return cell;
}
希望有人可以帮助我..
提前感谢.....
Im very new in xcode 3 and i really need help for this
I developed my apps using UITableView and XML to showed the content.
i had 3 .xib files which it rootViewController , SecondViewController and mainview.
So the problem is:
When i try to executed didSelectrow in rootViewController and access the NSMutableArray *array in SecondViewController and replace the *array value with new array value in rootViewController before pushed animation.
The array value on my SecondViewController was changed for the first time but when i pushed the back button and select the other row, my SecondViewController array kept read the previous array not change to a new one. I try to initialize but no luck
This is my code on rootViewController UITableview (didSelectRow):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(2ndController == nil)
2ndController = [[DetailViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
//Declare xml NSMutable array record
ListRecord *record = [self.entries objectAtIndex:indexPath.row];
//access SecondViewController NSMutable *record
2ndController.record = [[[NSMutableArray alloc] init] autorelease];
//inserting the value from firstview to secondview before push
2ndController.record = record;
//push animation
[self.navigationController pushViewController:2ndController animated:YES];
}
This is my second view controller :
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch(indexPath.section)
{
case 0:
[cell setText:record.name];
break;
case 1:
[cell setText:record.Age];
break;
case 2:
[cell setText:record.summary];
break;
}
return cell;
}
Hope someone can help me..
Thanks in advance.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几件事
您做了
,然后跟进
显然,
record
属性似乎不是NSMutableArray
的实例,所以我认为数组初始化部分不正确,因为你确实这样做了,并且已经提到过,但我认为问题是你保留了
UITableViewController
子类。您是否尝试过重新加载数据?将其添加到
DetailViewController
的viewWillAppear
方法中。Few things,
You do,
and follow it up with
Clearly, the
record
property doesn't seem to be an instance ofNSMutableArray
so I think the array initialization part is incorrect as you do, and already mentioned,But the problem I think is that you are retaining your
UITableViewController
subclass. Have you tried reloading the data?Add it in the
viewWillAppear
method of yourDetailViewController
.您应该再次查看这两行:
第一行对您没有任何用处。它创建并初始化一个新的 NSMutableArray 并将记录属性设置为该新数组。
但是,然后在下一行中,您再次将相同的“记录”属性设置为不同的对象,以便不再引用第一行中的数组。所以你可能还没有创建过它。
确切地说,这不是你的问题,但这个评论对于评论来说太大了。 :)
You should look at these two lines again:
The first line doesn't do anything useful for you. It creates and initializes a new NSMutableArray and sets the record property to that new array.
But then in the very next line you set the same 'record' property again to a different object and so that array in the first line is no longer referenced. So you might as well not have ever created it.
That's not your issue exactly, but this comment was too big for a comment. :)