点击就像所有的视图应该显示像是一个O型C [英] Clicking on Like all the view should show like ojective C

查看:108
本文介绍了点击就像所有的视图应该显示像是一个O型C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击按钮时,如果我点击 Throwback - > 描述 >和like count = 1099增加。如果我按回来,我希望这个不像显示在 Throwback 旁边的一个标签中,再次选择 Throwback 按钮应该显示不一样,Count应该是1100.
请帮助我如何实现这一点?

When I select Throwback -> Description occurs if I click on like button the like button changes to unlike and " like count=1099" increases. If I press back I want this unlike to be displayed next to Throwback let say in a label and again select Throwback button should display unlike and like Count should be 1100. please Help how can i achieve this ?

// DetailOfUser.m

//DetailOfUser.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

//

//DetailsOfStories.m

#import "DetailOfUser.h"
@interface DetailsOfStories ()
{
    NSMutableArray *descriptionList;
BOOL buttonToggled;
    int number,number1;
    NSNumber *num1;
}
@end
@implementation DetailsOfStories
@synthesize descriptionList;
- (void)viewDidLoad {
   UILabel *like_count=(UILabel *)[self.view viewWithTag:3];
    NSNumber *someNumber = @(number);
    NSString *someString = [someNumber stringValue];
    like_count.text=someString;
}
- (IBAction)like:(id)sender {

    if (!buttonToggled) {
        [sender setTitle:@"Unlike" forState:UIControlStateNormal];
        //number is interger
        number = [num1 intValue]+1;
        number1=number;
        UILabel *like_count=(UILabel *)[self.view viewWithTag:3];
        NSNumber *someNumber = @(number);
        NSString *someString = [someNumber stringValue];
        like_count.text=someString;
        buttonToggled = YES;
    }
    else {
        [sender setTitle:@"Like" forState:UIControlStateNormal];
        number1 = number1-1;
        UILabel *like_count=(UILabel *)[self.view viewWithTag:3];
        NSNumber *someNumber = @(number1);
        NSString *someString = [someNumber stringValue];
        like_count.text=someString;
        buttonToggled = NO;
    }
}


推荐答案

你可以将喜欢号码和状态封装到数据模型中。

您的控制器都可以访问和修改数据模型。在这种情况下,数据模型可以是单例,以便您可以在控制器中获取它。

可能您需要将数据同步到服务器或持久性数据到本地存储之后,数据模型可以封装所有这些服务。

You can encapsulate the 'likes' number and status into a data model.
Both your controllers can access and modify the data model. In this case, data model can be a singleton, so that you can acquire it in your controllers.
May be you need sync data to server or persistent data to local storage later, data model can encapsulate all this service.

这是一些代码示例

// 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()委托中更新like status。您可以查看有关苹果官方文档的详细信息。

If you want to update your story viewcontroller back from detail page. You can update 'like status' in its viewWillAppear() delegate. You can check details on Apple's official document.

这篇关于点击就像所有的视图应该显示像是一个O型C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆