gpt4 book ai didi

ios - 如何更新 TableView 静态单元格中的数据?

转载 作者:行者123 更新时间:2023-12-01 19:52:12 24 4
gpt4 key购买 nike

我想更新计数的值,但我不能这样做..!我试过了,但是当我构建代码时它会更新......!

这是一个表格 View 的屏幕截图:

1

这是此的代码,

#import "LeftMenuViewController.h"
#import "RKDropdownAlert.h"
#import "HexColors.h"
#import "AppConstanst.h"
#import "GlobalVariables.h"
#import "MyWebservices.h"
#import <SDWebImage/UIImageView+WebCache.h>
@import Firebase;
@interface LeftMenuViewController (){
NSUserDefaults *userDefaults;
GlobalVariables *globalVariables;
NSArray *numbers;
}
@end

@implementation LeftMenuViewController

- (id)initWithCoder:(NSCoder *)aDecoder
{
self.slideOutAnimationEnabled = YES;

return [super initWithCoder:aDecoder];
}

- (void)viewDidLoad {
[super viewDidLoad];

NSLog(@"Naaa-LeftMENU");


self.tableView.tableFooterView=[[UIView alloc] initWithFrame:CGRectZero];

}

-(void)viewWillAppear:(BOOL)animated{

userDefaults=[NSUserDefaults standardUserDefaults];
globalVariables=[GlobalVariables sharedInstance];
NSLog(@"Role : %@",[userDefaults objectForKey:@"role"]);
_user_role.text=[[userDefaults objectForKey:@"role"] uppercaseString];

_user_nameLabel.text=[userDefaults objectForKey:@"profile_name"];
_url_label.text=[userDefaults objectForKey:@"baseURL"];

[_user_profileImage sd_setImageWithURL:[NSURL URLWithString:[userDefaults objectForKey:@"profile_pic"]]
placeholderImage:[UIImage imageNamed:@"default_pic.png"]];
_user_profileImage.layer.borderColor=[[UIColor hx_colorWithHexRGBAString:@"#0288D1"] CGColor];

_user_profileImage.layer.cornerRadius = _user_profileImage.frame.size.height /2;
_user_profileImage.layer.masksToBounds = YES;
_user_profileImage.layer.borderWidth = 0;



NSInteger open = [globalVariables.OpenCount integerValue];
NSInteger closed = [globalVariables.ClosedCount integerValue];
NSInteger trash = [globalVariables.DeletedCount integerValue];
NSInteger unasigned = [globalVariables.UnassignedCount integerValue];
NSInteger my_tickets = [globalVariables.MyticketsCount integerValue];

if(open>999){
_inbox_countLabel.text=@"999+";
}else
_inbox_countLabel.text=@(open).stringValue;
if(closed>999){
_closed_countLabel.text=@"999+";
}else
_closed_countLabel.text=@(closed).stringValue;
if(trash>999){
_trash_countLabel.text=@"999+";
}else
_trash_countLabel.text=@(trash).stringValue;
if(unasigned>999){
_unassigned_countLabel.text=@"999+";
}else
_unassigned_countLabel.text=@(unasigned).stringValue;
if(my_tickets>999){
_myTickets_countLabel.text=@"999+";
}else
_myTickets_countLabel.text=@(my_tickets).stringValue;

[self.tableView reloadData];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
bundle: nil];

// UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

UIViewController *vc ;

switch (indexPath.row)
{
case 1:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"CreateTicket"];
break;

case 2:
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
break;
case 3:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"InboxID"];
break;
case 4:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"MyTicketsID"];
break;
case 5:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"UnassignedTicketsID"];
break;
case 6:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"ClosedTicketsID"];
break;

case 7:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"TrashTicketsID"];
break;

case 8:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"ClientListID"];
break;

case 10:
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"AboutVCID"];
break;


case 11:

[self wipeDataInLogout];
//[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
//[[SlideNavigationController sharedInstance] popToRootViewControllerAnimated:NO];

[RKDropdownAlert title:@"Faveo Helpdesk" message:@"You've logged out, successfully." backgroundColor:[UIColor hx_colorWithHexRGBAString:SUCCESS_COLOR] textColor:[UIColor whiteColor]];
vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"Login"];
// (vc.view.window!.rootViewController?).dismissViewControllerAnimated(false, completion: nil);
break;


default:
break;
}

[[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:vc
withSlideOutAnimation:self.slideOutAnimationEnabled
andCompletion:nil];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

if (indexPath.row == 9) {
return 0;
} else {
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}

}

-(void)wipeDataInLogout{

[self sendDeviceToken];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"faveoData.plist"];
NSError *error;
if(![[NSFileManager defaultManager] removeItemAtPath:plistPath error:&error])
{
NSLog(@"Error while removing the plist %@", error.localizedDescription);
//TODO: Handle/Log error
}

NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *each in cookieStorage.cookies) {
[cookieStorage deleteCookie:each];
}

}

-(void)sendDeviceToken{

// NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
NSString *url=[NSString stringWithFormat:@"%@fcmtoken?user_id=%@&fcm_token=%s&os=%@",[userDefaults objectForKey:@"companyURL"],[userDefaults objectForKey:@"user_id"],"0",@"ios"];
MyWebservices *webservices=[MyWebservices sharedInstance];
[webservices httpResponsePOST:url parameter:@"" callbackHandler:^(NSError *error,id json,NSString* msg){
if (error || [msg containsString:@"Error"]) {
if (msg) {

// [utils showAlertWithMessage:[NSString stringWithFormat:@"Error-%@",msg] sendViewController:self];
NSLog(@"Thread-postAPNS-toserver-error == %@",error.localizedDescription);
}else if(error) {
// [utils showAlertWithMessage:[NSString stringWithFormat:@"Error-%@",error.localizedDescription] sendViewController:self];
NSLog(@"Thread-postAPNS-toserver-error == %@",error.localizedDescription);
}
return ;
}
if (json) {

NSLog(@"Thread-sendAPNS-token-json-%@",json);
}

}];
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// rows in section 0 should not be selectable
// if ( indexPath.section == 0 ) return nil;

// first 3 rows in any section should not be selectable
if ( (indexPath.row ==0) || (indexPath.row==2) ) return nil;

// By default, allow row to be selected
return indexPath;
}


@end

最佳答案

做一件事,在 viewDidLoad 方法中添加类似的方法

[self update];

然后,在此方法中添加该代码。
-(void)update{


userDefaults=[NSUserDefaults standardUserDefaults];
globalVariables=[GlobalVariables sharedInstance];
NSLog(@"Role : %@",[userDefaults objectForKey:@"role"]);
_user_role.text=[[userDefaults objectForKey:@"role"] uppercaseString];

_user_nameLabel.text=[userDefaults objectForKey:@"profile_name"];
_url_label.text=[userDefaults objectForKey:@"baseURL"];

[_user_profileImage sd_setImageWithURL:[NSURL URLWithString:[userDefaults objectForKey:@"profile_pic"]]
placeholderImage:[UIImage imageNamed:@"default_pic.png"]];
_user_profileImage.layer.borderColor=[[UIColor hx_colorWithHexRGBAString:@"#0288D1"] CGColor];

_user_profileImage.layer.cornerRadius = _user_profileImage.frame.size.height /2;
_user_profileImage.layer.masksToBounds = YES;
_user_profileImage.layer.borderWidth = 0;


_view1.alpha=0.5;
_view1.layer.cornerRadius = 20;
_view1.backgroundColor = [UIColor purpleColor];

_view2.alpha=0.5;
_view2.layer.cornerRadius = 20;
_view2.backgroundColor = [UIColor purpleColor];


_view3.alpha=0.5;
_view3.layer.cornerRadius = 20;
_view3.backgroundColor = [UIColor purpleColor];


_view4.alpha=0.5;
_view4.layer.cornerRadius = 20;
_view4.backgroundColor = [UIColor purpleColor];

_view5.alpha=0.5;
_view5.layer.cornerRadius = 20;
_view5.backgroundColor = [UIColor purpleColor];


NSInteger open = [globalVariables.OpenCount integerValue];
NSInteger closed = [globalVariables.ClosedCount integerValue];
NSInteger trash = [globalVariables.DeletedCount integerValue];
NSInteger unasigned = [globalVariables.UnassignedCount integerValue];
NSInteger my_tickets = [globalVariables.MyticketsCount integerValue];

if(open>99){
_c1.text=@"99+";
}else
_c1.text=@(open).stringValue;
if(closed>99){
_c4.text=@"99+";
}else
_c4.text=@(closed).stringValue;
if(trash>99){
_c5.text=@"99+";
}else
_c5.text=@(trash).stringValue;
if(unasigned>99){
_c3.text=@"99+";
}else
_c3.text=@(unasigned).stringValue;
if(my_tickets>99){
_c2.text=@"99+";
}else
_c2.text=@(my_tickets).stringValue;

[self.tableView reloadData];

}

并添加此代码,
-(void)viewWillAppear:(BOOL)animated{

[self.tableView reloadData];
//[self.tableView reloadData];

}

并在 viewDidLoad 方法中调用 getDependencies 方法。
检查一次,让我知道..!

关于ios - 如何更新 TableView 静态单元格中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45094420/

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