2013-05-29 2 views
0

안녕하세요, 텍스트 필드, tableview 및 단추가있는 응용 프로그램을 만들려고합니다. 버튼을 누르면 텍스트 필드의 정보가 테이블 뷰에 추가됩니다. 이 튜토리얼을 언제 찾을 수 있습니까? 나는 책에 하나를 가지고 있지만 그것을 찾을 수 없습니다. 미리 감사드립니다. 하는 .m텍스트 필드에서 테이블보기로 정보로드

- (void)viewDidLoad{ 
    [super viewDidLoad]; 
    self.textonota.delegate = self; 

// Do any additional setup after loading the view. 

}

- (void)didReceiveMemoryWarning 
    { 
    [super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 
    - (BOOL)textFieldShouldReturn:(UITextField *)textField { 
[textField resignFirstResponder]; 
return NO; 
} 
- (IBAction)AddNota:(id)sender { 
[arrayNota addObject: textonota.text]; 
[tableNota reloadData]; 

}

//TableView------------------------------------ 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [arrayNota count]; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 
- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] init]; 
} 
cell.textLabel.text = [arrayNota objectAtIndex: indexPath.row]; 
return cell; 
} 
//---------------------------------------------- 

@end 
의 .H

@interface BlockNotasViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { 
IBOutlet UITableView *tableNota;} 

@property (strong, nonatomic) IBOutlet UITextField *textonota; 
@property (nonatomic, retain) IBOutlet UITableView *tableNota; 
@property (nonatomic, strong) NSMutableArray * arrayNota; 
- (IBAction)AddNota:(id)sender; 
@end 

코드의

코드 : 여기에 지금까지 내 코드입니다

더 이상의 오류는 없지만 버튼은 아무 것도 수행하지 않습니다.

답변

0

tableView에 추가 할 모든 셀을 포함하는 NSMutableArray 속성을 설정할 수 있습니다.

그 버튼을 누르면, 당신은 당신의 UITextField의 텍스트에 태그와 세포, 그리고 셀의 설정 텍스트 작성 :

cell.textLabel.text = aUITextField.text; 

가 그있는 NSMutableArray에 셀을 추가, 그리고 [있는 tableView 전화 reloadData]를 사용하여 테이블 뷰를 새로 고칩니다. cellForRowAtIndexPath에서

: indexPath 위임, 당신은 예를 들어, 반환있는 NSMutableArray에있는 셀을 결정하기 위해 해당 태그를 사용할 수 있습니다

[return [self.cellArray objectAtIndex:indexPath.row]]; 

희망이 도움이! :)

+0

예, 어떻게 할 지에 대한 아이디어를 제공하지만 제가 따라야 할 가이드를 알고 있습니까? – darkjuso

+0

내가 문제가있는 것들은 셀에있는 배열이고 버튼에 무엇을 넣어야합니까? 오류의 경우 – darkjuso

+0

, 현재 클래스가 UITableView의 하위 클래스입니까? UIView UITableView의 대리자 메서드를받는 것처럼 보입니다. 다음은 UITableView 튜토리얼입니다 : http : //www.iosdevnotes.com/2011/10/uitableview-tutorial/ – coolbeet

0

문자열로 가변 배열을 유지해야합니다. 그리고이 배열을 사용하여 tableview의 내용을 데이터 소스로 채 웁니다. 위임 방법에 - (있는 UITableViewCell *)있는 tableView : cellForRowAtIndexPath : 아이폰 OS 개발자를위한

- (UITableViewCell*) tableView: (UITableView*) tableView 
     cellForRowAtIndexPath: (NSIndexPath*) indexPath 
{ 
    UITableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier: @"identifier"]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault 
             reuseIdentifier: @"identifier"] autorelease]; 
    } 
    cell.textLabel.text = [myMutableArray objectAtIndex: indexPath.row]; 
    return cell; 
} 

- (NSInteger)tableView: (UITableView*) tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [myMutableArray count]; 
} 

- (IBAction) pressButton: (id) sender 
{ 
    [myMutableArray addObject: textField.text]; 
    [myTableView reloadData]; 
} 

모든 책이 jQuery과에 대한 정보가 포함되어 다음과 같이 필요한 경우가있는 UITableViewCell을 생성합니다. 읽어주세요 https://stackoverflow.com/questions/3403049/best-book-resources-for-learning-ios-programming

+0

안녕하세요. 코드를 사용했지만 오류가 있습니다. 원래 게시글에 넣었습니다. – darkjuso

+0

코드가 업데이트되었지만 버튼에 오류가 발생했습니다. – darkjuso

관련 문제