이 경우 어떻게 작동합니까? NSMutabeArray * dataSource를 만들었습니다.Button을 사용하여 셀을 추가하는 방법은 무엇입니까?
: 내 .H 파일에 있지만, 오류의 무리 받고 "RootViewController.m : 오류 : 시맨틱 문제를 : 부동산 '은 dataSource가' 'RootViewController *'유형의 객체를 찾을 수 없습니다"
RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
NSMutableArray *dataSource;
}
@property (nonatomic,retain) NSMutableArray *dataSource;
- (IBAction)addButton:(id)sender;
@end
RootViewController.m
#import "RootViewController.h"
@implementation RootViewController
@synthesize dataSource;
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataSource = [NSMutableArray arrayWithCapacity:1];
//adds right bar button.
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
self.navigationItem.rightBarButtonItem=addButton;
[addButton release];
}
-(void)addButton:(id)sender{
[self.dataSource addObject:@"New Item"];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:[self.dataSource count] inSection:0];
[self.dataSource insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
더 좋은 방법이 있나요? – Jason
NSFetchedResultsController. –