当我选择 Throwback - > 说明如果我点击喜欢按钮,则类似按钮变为与和"像count = 1099"增加。如果我按回来,我希望不像显示在 Throwback 旁边,请在标签中显示,然后再次选择 Throwback 按钮应显示不像和Count应该是1100。 请帮助我如何实现这一目标?
// DetailOfUser.m
- name: Bootrstrap python
hosts: localhost
tasks:
raw: sudo apt-get update && sudo apt-get -y python-simplejson
delegate_to: '{{ item }}'
with_items: {{ groups["hosts"] }}
// DetailsOfStories.m
#impot"DetailsOfStories.h"
@interface DetailOfUser ()<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *arrayAboutList;
DetailsOfStories *viewController;
}
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
UILabel *title=[(UILabel *)cell viewWithTag:2];
title.text=[NSString stringWithFormat:@"%@", [arrayAboutList[indexPath.row] valueForKey:@"title"]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"DetailsOfStories"];
viewController.descriptionList = [arrayAboutList[indexPath.row] mutableCopy];
[self.navigationController pushViewController:viewController animated:YES];
}
@end
答案 0 :(得分:0)
您可以将“赞”号和状态封装到数据模型中
您的控制器都可以访问和修改数据模型。在这种情况下,数据模型可以是singleton
,以便您可以在控制器中获取它
可能是您需要将数据同步到服务器或将持久数据同步到本地存储,数据模型可以封装所有这些服务。
以下是一些代码示例
// YourDataModel
@interface YourDataModel : NSObject
@property (nonatomic, assign) NSNumber *numbersOfLike;
@property (nonatomic, assign) BOOL like;
@end
@implemention
+ (id)shareInstance {
static dispatch_once_t onceToken;
static YourDataModel *model;
dispatch_once(&onceToken, ^{
model = [[YourDataModel alloc] init];
});
return model;
}
// maybe sync data to backend server.
- (void)sync {
}
// load like numbers from local storage or remote server
- (instancetype)init {
}
// Then you can use it in your controllers
[[YourDataModel shareInstance] like];
[[YourDataModel shareInstance] numbersOfLike];
[[YourDataModel shareInstance] setLike:false];
更新
如果您想从详细信息页面更新故事视图控制器。您可以在其viewWillAppear()
代理中更新“状态”。您可以查看Apple's official document上的详细信息。