在单击按钮的iphone上更改表视图中的数据
我是iPhone应用程序开发新手。 在我的应用程序中,当我单击搜索按钮时,我想在表视图中显示记录。 我正在使用数组更改表视图中的记录,但它不起作用。请帮助 viewController.m在单击按钮的iphone上更改表视图中的数据,iphone,ios,uitableview,Iphone,Ios,Uitableview,我是iPhone应用程序开发新手。 在我的应用程序中,当我单击搜索按钮时,我想在表视图中显示记录。 我正在使用数组更改表视图中的记录,但它不起作用。请帮助 viewController.m -(iAction)打印按钮按下:(id)发件人 { mylabel.text=keyfileld.text; UITableView*表格视图; nsindepath*indepath; mylabel.text=keyfileld.text; NSString*post=[NSString stringW
-(iAction)打印按钮按下:(id)发件人
{
mylabel.text=keyfileld.text;
UITableView*表格视图;
nsindepath*indepath;
mylabel.text=keyfileld.text;
NSString*post=[NSString stringWithFormat:@“username=%@”,keyfileld.text];
NSString*hostStr=@”http://demo.com/search_iphone.php?";
hostStr=[hostStr stringByAppendingString:post];
NSData*dataURL=[NSData datawithcontentsofull:[NSURL URLWithString:hostStr]];
NSString*serverOutput=[[NSString alloc]initWithData:dataURL编码:NSASCIIStringEncoding];
[各国删除ObjectForkey:@“1”];
[各国删除ObjectForkey:@“2”];
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=(UITableViewCell*)[tableView出列重用CellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier];
}
cell.textlab.text=[datasource objectAtIndex:indexath.row];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
if(服务器输出)
{
NSArray*listItems=[serverOutput组件由字符串分隔:@“#”];
UIAlertView*alertsuccess=[[UIAlertView alloc]initWithTitle:@“恭喜”消息:@“您已获得授权”
代表:自我取消按钮:@“确定”其他按钮:无,无];
[成功表演];;
mylabel.text=服务器输出;
NSMutableArray*stringArray=[[NSMutableArray alloc]init];
int x=1;
对于(int i=0;i尝试调用[tableView重载数据];将新数据加载到数组的…。为什么要在printButtonPressed方法中创建tableView和单元格?因为我想更改按钮按下事件的表内容。实际上,我想在iphone应用程序中开发搜索功能,从后端php应用程序中搜索记录。我从服务器获得了正确的php响应,但没有显示表视图结构中的ayed..plesae helpok,但是为什么要创建一个未在代码中使用的表视图?您应该已经有了一个表视图,然后用您的内容填充它,不是吗?是的,您是正确的。请忽略该表视图..现在请告诉我们ex///的chnage内容如何才能在回答时将答案标记为答案已到达。我使用了[tableView reloadData];但它仍然没有显示新数据…请帮助在调用reloadData之前,您是否已使用数据更新数组?当注释暗示未到达答案时,为什么将其标记为答案?
-(IBAction) printButtonPressed : (id) sender
{
mylabel.text =keyfileld.text;
UITableView *tableView ;
NSIndexPath *indexPath;
mylabel.text =keyfileld.text;
NSString *post =[NSString stringWithFormat:@"username=%@",keyfileld.text];
NSString *hostStr = @"http://demo.com/search_iphone.php?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
[states removeObjectForKey:@"1"];
[states removeObjectForKey:@"2"];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [datasource objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(serverOutput)
{
NSArray *listItems = [serverOutput componentsSeparatedByString:@"#"];
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
mylabel.text = serverOutput;
NSMutableArray *stringArray = [[NSMutableArray alloc] init];
int x=1;
for (int i=0;i<listItems.count; i++)
{
NSString *myString = [NSString stringWithFormat:@"%d",x];
NSArray *listItemsid = [[listItems objectAtIndex:i] componentsSeparatedByString:@","];
NSLog(@"place name at index %d: %@\n", i, [listItemsid objectAtIndex:1]);
[states setObject:[listItemsid objectAtIndex:1] forKey:myString];
x++;
[stringArray insertObject:[NSMutableArray arrayWithObjects:str,nil] atIndex:i];
}
datasource = [states allKeys];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
// [alertsuccess release];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
id aKey = [datasource objectAtIndex:indexPath.row];
cell.textLabel.text = [states objectForKey:aKey];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}