@property (nonatomic, strong) NSMutableArray *authorMutableArray;NSMutableArrayのは
- (id)init {
self = [super init];
if (self) {
self.authorMutableArray = [[NSMutableArray alloc] initWithObjects:@"First Row", @"Second Row", nil];
for (NSString *string in authorMutableArray) {
NSLog(@"String: %@", string);
}
NSLog(@"Init in Add Model with Author count:%i", [authorMutableArray count]);
}
}
(コードで)プロパティにアクセスする例を空にする。 NSLogは常に0としてカウントを表示します。
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row == [self.addModel.authorMutableArray count] - 1) {
NSLog(@"count of %i", [self.addModel.authorMutableArray count]);
return UITableViewCellEditingStyleInsert;
}
else {
return UITableViewCellEditingStyleDelete;
}
}
else {
return UITableViewCellEditingStyleNone;
}
}
私がinitで作成している配列は、このメソッドを超えて値を保持していません。理由は何ですか? forループは配列内の両方のオブジェクトを表示します。 initメソッドが呼び出された後でこれを尋ねようとすると、配列は空です。
更新日時:皆さんありがとうございます。私はinitメソッドで自分自身を返すことを忘れていました。あなたのクラスのインターフェイスファイル(.hファイル)で
authormutablearrayプロパティの宣言方法 –
通常の合成プロパティです。 –
@WDysonウォーレンは何を意味していますか、どの指定者を使用していますか? '強い'、 '弱い'、 '割り当てる'?また、後でどのようにアレイにアクセスしていますか?そのコードを私たちに見せてもらえますか? –