English 中文(简体)
NSArray在3次观察后确实装载了。
原标题:NSArray clears after 3 times view did load

我有一个包含几个项目的NSArray。 国家航空航天局从另一个类别装上了一张可核实的概览。 当我放弃详细的看法和重新进入(第3次)时,国家空间局是空洞的,表象也是空洞的。 正在发生什么? (我使用了弧线,因此我认为它是一种泄漏)

- (void)viewDidLoad {

    myMatch = [[Match alloc] initWithId:1 OpponentId:13];
}


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

    static NSString *askCellIdent = @"askCell";
    static NSString *answerCellIdent = @"answerCell";


    if (indexPath.row == 0)
    {

        AskCell *cell = [tv dequeueReusableCellWithIdentifier:askCellIdent];
        if (cell==nil) {
            cell = [[AskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:askCellIdent];
        }

        cell.nameLabel.text = @"Albert asked:";
        cell.questionLabel.text = [NSString stringWithFormat:@"%@", [[myMatch.chat objectAtIndex:indexPath.row] objectAtIndex:1]];
        return cell;
    }
    if (indexPath.row == 1)
    {

        AnswerCell *cell = [tv dequeueReusableCellWithIdentifier:answerCellIdent];
        if (cell==nil) {
            cell = [[AnswerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:answerCellIdent];
        }

        cell.nameLabel.text = @"Hugh answered:";
        cell.answerLabel.text = [NSString stringWithFormat:@"%@", [[myMatch.chat objectAtIndex:indexPath.row] objectAtIndex:1]];
        return cell;
    }

}

这里是我同级的随身守则:

- (id) initWithId:(NSInteger)yourId OpponentId:(NSInteger)opId {
    self = [super init];
    if (self != nil) {
        //set your id and opponents id to the match.
        [self setUserId:yourId];
        [self setUserId:opId];

        JSON = @"[{"opponentId":"4","chat":[["1","Does he have a beard?"],["1","No."]]}]";

        //initiate the chat array.
        chat = [[NSMutableArray alloc] init ];
        [self loadMatch];


    }
    return self;
}

这里是动产/动产。

NSMutableArray *chat;

@property (nonatomic, retain) NSMutableArray *chat;

@synthesize chat;

No idea whats going on, because the slog of the array is empty too!

最佳回答

app app

- (void)viewDidLoad
{
    [super viewDidLoad];
    ypurAppDelegate *appDelegate = (yourAppDelegate *)[[UIApplication sharedApplication]   elegate];


          appDelegate.repeatCount++;

       if(appDelegate.repeatCount %3==0)
       {
           [array removeAllObjects];
            [tableview reloaddata];
        }
}
问题回答

自行使用:

相反的观点 DidLoad, 将物体分配到InitWithCoder。

- (void)viewDidLoad
{
   [super viewDidLoad];
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if( self )
    {
       myMatch = [[Match alloc] initWithId:1 OpponentId:13];
    }
return self;
}

我认为,仅一次将打电话到<代码>viewDidLoad<<<>>/code>,就是一个人口构成的问题。 您应在<条码>上插入各种数值。 方法或启动<代码>initWithCoder的对应类别。





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签