2013-03-25 3 views
1

사용자가 저장 버튼을 클릭하면 NSUserDefaults 유형의 변수에 사용자의 정보를 저장합니다. 나는 응용 프로그램의 시작을 원하고, 설정은 해당 셀에 저장할 수 있습니다. 그래서 여기에 viewDidLoad 메서드의 해당 파일에서 수행 한 작업이 있습니다.NSDictionary의 데이터로 UITableView의 셀 텍스트를 변경하는 방법

- (void)viewDidLoad 
{ 
    // [super viewDidLoad]; 
// Do any additional setup after loading the view. 

    if (self.navigationPaneBarButtonItem) 
      [self.navigationBar.topItem setLeftBarButtonItem:self.navigationPaneBarButtonItem 
                          animated:NO]; 

    //Initialise IndexPath 
    NSIndexPath *indexPathBroker = [NSIndexPath indexPathForRow:0 inSection:0]; 
    NSIndexPath *indexPathPort = [NSIndexPath indexPathForRow:1 inSection:0]; 

    NSUserDefaults *defaultConf; 
    defaultConf=[NSUserDefaults standardUserDefaults]; 
    NSString * broker =[defaultConf stringForKey:@"broker"]; 
    NSString *port= [defaultConf stringForKey:@"port"]; 
    NSLog(@"Brokerdidload: %@ et Portdidload: %@",broker,port); 

    //Create strings and integer to store the text info 
    ConfigDetailEditTableCell *editCellBroker = (ConfigDetailEditTableCell *)[_tableView cellForRowAtIndexPath:indexPathBroker]; 
    ConfigDetailEditTableCell *editCellPort = (ConfigDetailEditTableCell *)[_tableView cellForRowAtIndexPath:indexPathPort]; 


    //set data 
      editCellPort.EditCellValue.text =port; 
    editCellBroker.EditCellValue.text=broker; 
    // [editCellBroker.EditCellValue setText:broker]; 
    // [[editCellPort textLabel] setText:port]; 
    // [[editCellBroker textLabel] setText:broker]; 
    // [[editCellPort textLabel] setPlaceholder:port]; 
    // [[editCellBroker textLabel] setPlaceholder:broker]; 
    // editCellPort.EditCellValue.text =*/ 


    NSLog(@"editCellPort.EditCellValue: %@ et editCellBroker.EditCellValue: %@",editCellPort.EditCellValue.text,editCellBroker.EditCellValue.text); 

} 

브로커 및 포트의 변수에 정보가 있지만 셀을 업데이트하려고 시도하면 작동하지 않습니다. 내가 마지막으로 사용하는 NSLog Null 참조

치료 방법 ???

- (void)viewDidLoad 
{ 
    // [super viewDidLoad]; 
// Do any additional setup after loading the view. 

    if (self.navigationPaneBarButtonItem) 
      [self.navigationBar.topItem setLeftBarButtonItem:self.navigationPaneBarButtonItem 

    //Rest are not needed 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     //Initialize cell 


     NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults]; 
     NSString * broker =[defaults stringForKey:@"broker"]; 
     NSString *port= [defaults stringForKey:@"port"]; 

     cell.EditCellValue.text = indexPath.row==0?broker:port; 

     return cell; 

} 
+0

왜 'cellForRowAtIndexPath'에서 indexPaths를 테스트하고 그 값을 설정해야합니까? 또한, 대문자의 프로퍼티 명 ('EditCellValue' 등)을 사용하지 말아주세요. 그렇지 않은 경우는, 정말로 당신의 코드를 싫어할 것입니다. 또한,'viewDidLoad'를 오버라이드 할 때 항상 [super viewDidLoad];를 호출해야합니다. – mrueg

+0

그게'viewDidAppear'이어야합니까? – mrueg

+0

viewWillAppear을 시도했습니다. viewWillAppear 안에 viewDidLoad 메서드의 내용을 복사하여 붙여 넣었습니다. 그러나 나는 똑같은 실수를했다. – Franky

답변

1

대신 사전에 감사합니다 NSUserDefaults에서 자동으로 데이터를 가져 와서 테이블보기에 표시합니다. 또한 NSUserDefaults에 다시 입력 된 모든 데이터를 자동으로 저장합니다. 매우 편리합니다.

+0

감사합니다. Anupdas 작동합니다, – Franky

+0

@Pisix 답변을 올바른 것으로 표시하는 것이 좋습니다. 해피 코딩 :) – Anupdas

0

또한 무료 분별있는 TableView 프레임 워크를 사용할 수있는 tableView의은 dataSource 방법 :

당신이 cellForRowAtIndexPath에서 그것을해야한다있는 viewDidLoad에서 셀의 값을 설정하려고의

관련 문제