0

我试图根据 if 语句有条件地隐藏我的 UITableView。

现在我有以下代码,当我加载应用程序时,它会检查条件并且可以正常工作,当我按下重新加载按钮时,它会检查并且可以正常工作。

我也有一个 ViewWillAppear 语句,如果我更改视图并再次返回 TableView,它将起作用。

现在我的问题是我需要什么 void 或方法来自动执行此操作 - 即无需按下按钮或更改视图?

现在代码显示了我拥有的 3 种方法,它们或多或少都具有相同的代码,以显示我到目前为止所拥有的。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//self.navigationItem.leftBarButtonItem = self.editButtonItem;

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;

// Change Color of TableView if Empty
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
    //I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
    [_tableView setAlpha:1.0];
    [self.tableView setBackgroundColor:[UIColor purpleColor]];
}
else if ([[self.fetchedResultsController fetchedObjects] count] > 0 ) {
    //I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
    [_tableView setAlpha:1.0];
    [self.tableView setBackgroundColor:[UIColor yellowColor]];
    NSLog (@"");
}
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

// Change Color of TableView if Empty
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
    //I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
    [_tableView setAlpha:1.0];
    [self.tableView setBackgroundColor:[UIColor purpleColor]];
}
else if ([[self.fetchedResultsController fetchedObjects] count] > 0 ) {
    //I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
    [_tableView setAlpha:1.0];
    [self.tableView setBackgroundColor:[UIColor yellowColor]];
    NSLog (@"");
}
}




-(IBAction)ReloadAction{

// Change Color of TableView if Empty
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
    //I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
    [_tableView setAlpha:1.0];
    [self.tableView setBackgroundColor:[UIColor purpleColor]];
}
else if ([[self.fetchedResultsController fetchedObjects] count] > 0 ) {
    //I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
    [_tableView setAlpha:1.0];
    [self.tableView setBackgroundColor:[UIColor yellowColor]];
    NSLog (@"");
}
[_tableView reloadData];
//[_tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}

干杯杰夫

4

1 回答 1

0

我想到了

我将 if 语句添加到定义 + 符号的位置以及代码中设置删除方法的位置:-)

不管怎么说,还是要谢谢你:-)

于 2012-04-19T04:42:39.267 回答