我已经彻底寻找解决方案,并没有找到一个。这似乎是我想要做的基本内容,但是我迄今为止阅读的所有网页都没有解决这些问题。通过get方法在另一个nib中显示来自NSMutable Array的数据?
我有两套3常用文件。
- MyTableViewController.h .M的.xib
- TableViewDetails.h .M的.xib
当用户点击在MyTableViewController.xib一行时,它显示TableViewDetails.xib与内容在MyTableViewController中声明/填充的数组。
- 为了演示起见,我想通过将项目数量排调用数组(tableDataList)
那么,如何实现这一目标,其认为可以实现这个代码被注释掉?
MyTableViewController.h
@interface MyTableViewController : UITableViewController {
NSMutableArray *tableDataList;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navCont;
@property (nonatomic, readwrite, retain) NSMutableArray *tableDataList;
//+ (NSString *)getTempArray:(int)number;
//- (NSString *) getTempArray_m: (int) number;
@end
MyTableViewController.m
//#import "MyTableViewController.h"
#import "TableViewDetailsView.h"
@implementation MyTableViewController
@synthesize tableDataList;
- (void)viewDidLoad
{
NSMutableArray *tempArray = [[[NSMutableArray alloc] initWithObjects:@"Item 1",@"Item 2",@"Item 3",@"Item 4",@"Item 5",@"Item 6", nil] autorelease];
tableDataList = [[NSMutableArray alloc] init];
tableDataList = tempArray;
}
//+ (NSString *)getTempArray:(int)number {
// return [MyTableViewController getTempArray_m: number];
//}
//
//- (NSString *)getTempArray_m:(int)number {
//
// return [self.tableDataList objectAtIndex:number];
//}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
NSLog(@"pushing...");
TableViewDetailsView *temp = [[[TableViewDetailsView alloc] initWithNibName:@"TableViewDetailsView"bundle:nil] autorelease];
// ...
// Pass the selected object to the new view controller.
[self.navCont pushViewController:temp animated:YES];
}
@end
MyTableViewController.h
#import <UIKit/UIKit.h>
//#import "MyTableViewController.h"
//@class MyTableViewController;
@interface TableViewDetailsView : UIViewController {
UIButton *buttonGetArray;
}
@end
TableViewDetailsView.m
#import "TableViewDetailsView.h"
//#import "MyTableViewController.h"
@implementation TableViewDetailsView
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// MyTableViewController *MyTableVC = [[MyTableViewController alloc] init]; - This is Wrong
// NSString *item = [MyTableViewController getTempArray:1];
// NSLog(@"The Array item: %@", item);
}
最后几句话,请您提供实际的代码更改,而不是填写此问题或提供链接到读数。我真的很想学习,但发现在这里没有解决简单的问题时,它不是非常有用。通过一切手段给我相关的信息指针,但首先在这里解决问题,以便未来的其他人可能受益更大。 感谢您花时间阅读我的问题。
程序现在终止在“temp.myDetailsString = ...;”行的didSelectRow方法中, - [NSCFString objectAtIndex:]:无法识别的选择发送到实例0x4e29760 ***由于未捕获的异常'NSInvalidArgumentException',原因:' - [NSCFString objectAtIndex:]:无法识别的选择发送到实例0x4e29760' '但有时myDetailsString是分配垃圾。 tableDataList中填充了数据,但是我无法在didSelectRow方法中读取它。 在这里找到xcode代码。 [TabNavTable_example 33kb](http://dl.dropbox.com/u/2128394/TabNavTable_example.zip) –
我得到的程序工作,但我不明白为什么Autorelease会停止阵列工作?...因此,我从这一行删除了autorelease。 NSMutableArray * tempArray = ..... 此外,我删除了self.tableDataList并将它留在tableDataList中。 终于 [UITableViews的一个有用的教程可以在这里找到](http://www.iphonesdkarticles.com/2009/01/uitableview-loading-detail-view.html) –
如果你的目标iOS 5你应该可能使用弧。不过,详细了解手动内存管理。 Ray Wenderlich的这篇文章是一篇很好的文章:http://www.raywenderlich.com/2657/memory-management-in-objective-c-tutorial –