に送信します。現時点では、私がシミュレータを実行すると、問題のtableViewは5行(これは正しい)が表示されますが、すべての行は同じ文字列です(これは明らかに正しくありません)。表示されている文字列は、NSMutableArrayで定義されているLASTオブジェクトのものです。ここでは、コードです:のaddObject:NSMutableArrayのを、私はNSMutableArrayのから移入だのtableViewを作成しようとしていますXcodeの4.2 iPhoneプロジェクト</p> <p>テーブルビュー
- (void)viewDidLoad
{
[super viewDidLoad];
codes = [[NSMutableArray alloc] init];
TableList *listItem = [[TableList alloc] init];
[listItem setCodeTitle:@"Test Name 1"];
[listItem setCodeNumber:@"101"];
[listItem setCodeDescription:@"This is the description for 101."];
[codes addObject:listItem];
[listItem setCodeTitle:@"Test Name 2"];
[listItem setCodeNumber:@"102"];
[listItem setCodeDescription:@"This is the description for 102."];
[codes addObject:listItem];
[listItem setCodeTitle:@"Test Name 3"];
[listItem setCodeNumber:@"103"];
[listItem setCodeDescription:@"This is the description for 103."];
[codes addObject:listItem];
[listItem setCodeTitle:@"Test Name 4"];
[listItem setCodeNumber:@"104"];
[listItem setCodeDescription:@"This is the description for 104."];
[codes addObject:listItem];
[listItem setCodeTitle:@"Test Name 5"];
[listItem setCodeNumber:@"105"];
[listItem setCodeDescription:@"This is the description for 105."];
[codes addObject:listItem];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
return [codes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CodeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
TableList *current = [codes objectAtIndex:indexPath.row];
cell.textLabel.text = [current codeTitle];
return cell;
}
私は、私は非常に少しを持っている...これは私よりも多くの経験を持つ人には痛いほど明白であると思います。
ありがとうございます、私はARCを使用していますので、そのクラスをリリースする必要はありません。また、ARCを使用しているため、自分のコードで自動解放機能を使用できなくなります。私はaddObject行を次のように置き換えようとしました: [code addObject:[listItem copy]]; tableViewが読み込もうとしたときにSIGABRTが表示されます。 おそらく、これは私のクラスがコピーをサポートしていないからでしょうか? –
@Paul:ARCでは 'autorelease'を省略できます。 SIGABRTはどのラインですか? 'TableList'が' 'に準拠していない場合、' -copy'の呼び出しは例外をスローします。 –
私のクラスTableListはNSObjectのサブクラスとして作成されました。私はこれがコピーを使用できると信じています。 –