我已經徹底尋找解決方案,並沒有找到一個。這似乎是我想要做的基本內容,但是我迄今爲止閱讀的所有網頁都沒有解決這些問題。通過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 –