사용자가 저장 버튼을 클릭하면 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;
}
왜 'cellForRowAtIndexPath'에서 indexPaths를 테스트하고 그 값을 설정해야합니까? 또한, 대문자의 프로퍼티 명 ('EditCellValue' 등)을 사용하지 말아주세요. 그렇지 않은 경우는, 정말로 당신의 코드를 싫어할 것입니다. 또한,'viewDidLoad'를 오버라이드 할 때 항상 [super viewDidLoad];를 호출해야합니다. – mrueg
그게'viewDidAppear'이어야합니까? – mrueg
viewWillAppear을 시도했습니다. viewWillAppear 안에 viewDidLoad 메서드의 내용을 복사하여 붙여 넣었습니다. 그러나 나는 똑같은 실수를했다. – Franky