objective-c - 如何重新加载 tableView,即如果满足条件则调用 viewDidLoad 方法

标签 objective-c ios uitableview

问题是,如果满足条件,我需要一种方法来基本上删除用户放入我的数组中的所有条目数据。我对 Objective-C 和 iOS 编程很陌生,但我相信解决方案可能是调用 viewDidLoad 方法,因此它实际上会刷新应用程序,并将数组的值重置为默认值。如果有任何其他合乎逻辑的方法可以做到这一点,我将不胜感激。

简而言之,我需要刷新数组,就像应用程序首次启动且用户未选择任何内容时一样。

这是我需要刷新的部分。

 if ([gradeRecieved objectAtIndex:i]==nil) {


            break; // if this condition is met the program must  begin anew.

编辑*我需要记忆 - (void)viewDidLoad 方法

这里是更多代码。

-(IBAction)button:(id)sender{
    double sum = 0;
    int i = 0;
    double gradeEarned=0;
    double creditHours = 3;

    while (i<8){

       // [credits removeObjectIdenticalTo:[NSNull null]];
        if ([credits count ] ==0) {
            break; 
        }

            if ([credits objectAtIndex:i] == radioButtonA) {

           // [gradeRecieved replaceObjectAtIndex:i withObject:GradeA];
                [defArray addObject:GradeA];
                gradeEarned+=GradeA.intValue;
                i++;
                continue;
            }

            if ([credits objectAtIndex:i] == radioButtonB) {
           // [gradeRecieved replaceObjectAtIndex:i withObject:GradeB];
                [defArray addObject:GradeB];
              gradeEarned+=GradeB.intValue;
                i++;
                continue;
            }

            if ([credits objectAtIndex:i]== radioButtonC){
         // [gradeRecieved replaceObjectAtIndex:i withObject:GradeC];
                [defArray addObject:GradeC];
                gradeEarned+=GradeC.intValue;
                i++;
                continue;

            }
        if ([credits objectAtIndex: i] == defaulter) {

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Custom button pressed" message:[NSString stringWithFormat:@"You pressed the custom button C"] delegate:self cancelButtonTitle:@"great"otherButtonTitles:nil];
            [alert show];
            [alert release];
        [self viewDidLoad];
            break;
        }
    }

    if ([defArray count]>0) {

                sum= ([defArray count])/(creditHours*gradeEarned);
        NSLog(@"%f",sum);}

但是,如果用户单击按钮然后尝试重做一些选择,此新代码会导致应用程序卡住

最佳答案

如果您想再次调用该代码,请将该代码包装到一个方法中,然后在 viewDidLoad 以及您想要的任何其他位置调用该方法。这是一些示例代码:

- (void)viewDidLoad {

  if ([gradeRecieved objectAtIndex:i]==nil) {


          [self refreshArray];
}

}

- (void)refreshArray {

   // refresh here


}

然后在任何需要的地方调用[selffreshArray]!

我看你是新来的!如果这个答案是正确的,您可以投票或勾选!

关于objective-c - 如何重新加载 tableView,即如果满足条件则调用 viewDidLoad 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10867080/

相关文章:

ios - UICollectionView 中的长按和平移手势

ios - 如何限制文本长度以适应动态创建的 UITextField 的宽度

ios - 自定义字体在 swift 3 中变为 nil 值

ios - 在滑动 Action 中滑动表格单元格重叠单元格内容

ios - 适用于所有屏幕尺寸的 Storyboard

iphone - UITableView 的默认标题 View

ios - swift - didUpdateLocations 未被调用

ios - 真正的随机 Xcode

ios - 苹果 watch : contexts not sending between view controllers

ios - UITableViewAutomaticDimension 引起的问题