[objective-c]显示出,如果之前单击过表单元格?

标签: ios Objective-C
发布时间: 2016/10/4 1:51:47
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我正在开发一个应用程序与新闻 feed。

这是 PFQueryTableView 从 parse.com 加载内容。

我也有一个细节 ViewController 附界限。

我的问题是︰

如何可以显示是之前尚未被单击的单元格?

喜欢在邮件在 IOS 中的应用。

这里是一个图片︰

http://i.stack.imgur.com/vO2N3.png

- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
    // Custom the table

    // The className to query on
    self.parseClassName = @"Nyhet";

    // The key of the PFObject to display in the label of the default cell style
    self.textKey = @"Rubrik";

    // Whether the built-in pull-to-refresh is enabled
    self.pullToRefreshEnabled = YES;

    // Whether the built-in pagination is enabled
    self.paginationEnabled = YES;

    // The number of objects to show per page
    self.objectsPerPage = 10;
}
return self;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}


- (void)viewDidLoad
{
[super viewDidLoad];

// Change button color
sidebarButton.tintColor = [UIColor whiteColor];

// Set the side bar button action. When it's tapped, it'll show up the sidebar.
sidebarButton.target = self.revealViewController;
sidebarButton.action = @selector(revealToggle:);


// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

}


- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
/*    if ([self.objects count] == 0) {
    query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}*/

[query orderByDescending:@"Prioritering"];

return query;
}



// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the object.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *simpleTableIdentifier = @"RecipeCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

UILabel *nameLabel = (UILabel*) [cell viewWithTag:101];
nameLabel.text = [object objectForKey:@"Rubrik"];

UILabel *prepTimeLabel = (UILabel*) [cell viewWithTag:102];
prepTimeLabel.text = [object objectForKey:@"Detaljer"];



return cell;
}

- (void) objectsDidLoad:(NSError *)error
{
[super objectsDidLoad:error];

NSLog(@"error: %@", [error localizedDescription]);
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    RecipeDetailViewController *destViewController = segue.destinationViewController;

    PFObject *object = [self.objects objectAtIndex:indexPath.row];
    Recipe *recipe = [[Recipe alloc] init];
    recipe.name = [object objectForKey:@"Rubrik"];
    recipe.prepTime = [object objectForKey:@"Text"];
    recipe.detaljer = [object objectForKey:@"Detaljer"];
    recipe.rubriker = [object objectForKey:@"Rubrik"];
    destViewController.recipe = recipe;

}
}


@end

解决方法 1:

这是更好地使用自定义 UITableViewCell 示例︰

CustomTableViewCell.h
@interface CustomTableViewCell : UITableViewCell

@property(assign) bool beforeClicked

@end

CustomTableViewCell.m
#import CustomTableViewCell.h

@implementation CustomTableViewCell
@synthesize beforeClicked;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

@end

与示例︰

CustomTableViewCell.h //add 此标头
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
    static NSString *simpleTableIdentifier = @"RecipeCell";

    CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
         cell = (CustomTableViewCell *)[[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    UILabel *nameLabel = (UILabel*) [cell viewWithTag:101];
    nameLabel.text = [object objectForKey:@"Rubrik"];

    UILabel *prepTimeLabel = (UILabel*) [cell viewWithTag:102];
    prepTimeLabel.text = [object objectForKey:@"Detaljer"];

    cell.beforeClicked = NO;

    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    UITableViewCell *myCell = [tableView cellForRowAtIndexPath:indexPath];

    myCell.beforeClicked = YES;
}
官方微信
官方QQ群
31647020