gpt4 book ai didi

ios - 单击 TableView 中的按钮时从其他 View Controller 重新加载 UITableView

转载 作者:行者123 更新时间:2023-11-29 11:45:50 25 4
gpt4 key购买 nike

我在从其他 View Controller 调用时重新加载 UITableView 时遇到问题。我从 viewcontroller.m 调用了一个服务,结果显示在 tableviewcontroller.m 中。这是我的问题,我在 UITableViewCell 中有一个按钮,当单击一个按钮时,应该重新加载或刷新表格。

下面是我的代码:

viewController.m

NSString * post = [[NSString alloc]initWithFormat:@"country=%@&state=%@&userId=%@",_txtSearchField.text,UserId];


NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"url"]];


tableviewcontroller.m


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


static NSString *CellIdentifier = @"Cell";

customCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(!cell)
{
cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}


NSArray *arr=[[profileArr objectAtIndex:indexPath.row] allKeys];

cell.lblAge.text = [[[profileArr objectAtIndex:indexPath.row] valueForKey:key] valueForKey:@"Age"];

cell.lblLocation.text = [[[profileArr objectAtIndex:indexPath.row] valueForKey:key] valueForKey:@"Address"];

cell.lblProfession.text = [[[profileArr objectAtIndex:indexPath.row] valueForKey:key] valueForKey:@"Occupation"];

}

-(void)buttonclick:(id)sender
{
UIButton *btn = sender;

NSArray *arr=[[profileArr objectAtIndex:btn.tag] allKeys];
NSString *key=[arr objectAtIndex:0];

NSMutableDictionary *userDict=[[profileArr objectAtIndex:btn.tag] objectForKey:key];
NSString *str = [userDict objectForKey:@"UserId"];
[self callbuttonService:str];
}


-(void)callbuttonService:(NSString *)OtherUserId
{
//service is called
}

#pragma mark - MRConnection Delegate Methods

- (void)jsonData:(NSDictionary *)jsonDict
{
[SVProgressHUD dismiss];

NSMutableArray *jsonArr1;

jsonArr1=[jsonDict objectForKey:@"DataTable"];

if (![jsonArr1 isEqual:[NSNull null]]) {

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Employee" message:@"Sucess" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];

[self presentViewController:alertController animated:YES completion:nil];
[alertController.view setTintColor:[UIColor blackColor]];
}
else{
[SVProgressHUD showErrorWithStatus:@"Something went wrong!"];
}
}

最佳答案

根据您的问题,您在 viewcontroller.m 文件中调用了服务,并且您想在 tableviewcontroller.m 文件中重新加载 tableview。请试试这个。继续编码。

viewController.m

-(void)callbuttonService:(NSString *)OtherUserId
{
//service is called
}

#pragma mark - MRConnection Delegate Methods

- (void)jsonData:(NSDictionary *)jsonDict
{
[SVProgressHUD dismiss];

NSMutableArray *jsonArr1;

jsonArr1=[jsonDict objectForKey:@"DataTable"];

if (![jsonArr1 isEqual:[NSNull null]]) {

NSDictionary *DictionaryData = [[NSDictionary alloc]init];
[DictionaryData setValue:jsonArr1 forKey:@"data"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"tableReload" object:nil userInfo:DictionaryData];
}
else{
[SVProgressHUD showErrorWithStatus:@"Something went wrong!"];
}
}

tableviewcontroller.m

-(void)viewDidLoad() {
super.viewDidLoad()
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableReloadNotification:) name:@"tableReload" object:nil];

}
- (void) tableReloadNotification:(NSNotification *) notification {
NSDictionary *info = notification.userInfo;
if (info != nil) {
NSMutableArray *jsonArr1 = [info valueForKey:@"data"];
tableview.reloadData();
}
}

关于ios - 单击 TableView 中的按钮时从其他 View Controller 重新加载 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43975910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com