English 中文(简体)
iPhone:如何在已经装满的书目表征中增加一行?
原标题:iPhone: How to add rows in tableview after tabelview already loaded?

我已经为我的桌面应用实施了“对惠灵”功能。 除在运行期间将电池添加到我的惠物表观点之外,它还做了一些工作。 例如,我提供了以下方法。

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

    tableView.hidden = YES;
    warningLabel.hidden = YES;

    // Load any change in favourites
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *data = [defaults objectForKey:kFavouriteItemsKey];
    self.favourites = [NSKeyedUnarchiver unarchiveObjectWithData:data];

    if([self.favourites count] > 0) 
        tableView.hidden = NO;
    else 
        warningLabel.hidden = NO;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return [self.favourites count]; // Favorites is a dictionary contains required data
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [NSString stringWithFormat:@"index: %d",indexPath.row];

    return cell;
}

这部法典首次正确操作并显示行文! 在表征填满后,如果我增加新项目,赞成或删除任何项目,那么我的发言不会有任何改变。 我想确切地展示一下福克斯独裁者可以提供的东西。 看来,在GisoAppear再一次援引“CotForRowAtIndexPath”。 是否有我能用来满足我的要求的表态方法?

最佳回答

我认为你错失了<代码>。 数据:

问题回答

非常容易的做法是,在你作任何改动时,只打上<条码>。

还有一种较好的办法(大型桌子,可能 an灭;更远的主子),但除非你决定<条码>有效载荷/条码>,否则我所赢得的路程就更加复杂。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签