123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- //
- #import "DiaryVC.h"
- #import "CommunityCell.h"
- #import "PostTopicVC.h"
- #import "TopicVC.h"
- #import "STButton.h"
- @interface DiaryVC ()<UITableViewDataSource,UITableViewDelegate,CommunityCellDelegate>
- {
- NSMutableArray* models;
-
- UITableView* myTableView;
-
- /**每次下载后。就判断.
- 如果cnt为0就显示。否则隐藏
- */
- UIView* placeHolder;
-
- NSInteger currentPage;
- }
- @end
- @implementation DiaryVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- currentPage = 1;
- models = [NSMutableArray array];
-
- [self myInit];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- currentPage = 1;
- [self getTopicByUser];
- }
- #pragma mark -
- -(void)myInit
- {
- [self setTitle:@"我的学车日记"];
- [self configNavigationBar];
- //1.0.4 修复不能显示别人学车日记的bug
- self.view.backgroundColor = backGroundColor;
- if(![_userID isEqualToString:defUser.userDict[@"id"]])
- {
- [self setTitle:@"学车日记"];
- }
-
- //25+10
- UITableView* tv = [[UITableView alloc] initWithFrame:CGRectMake(25, 0, kSize.width - 35, kSize.height - kNavOffSet - 60 - kSafeAreaBottomHeight) style:UITableViewStyleGrouped];
- [tv setBackgroundColor:backGroundColor];
- [self.view addSubview:tv];
- [tv setDelegate:self];
- [tv setDataSource:self];
- tv.estimatedSectionFooterHeight = 0;
- myTableView = tv;
- [tv setTableFooterView:[UIView new]];
-
- if ([tv respondsToSelector:@selector(setSeparatorInset:)])
- {
- [tv setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([tv respondsToSelector:@selector(setLayoutMargins:)])
- {
- [tv setLayoutMargins:UIEdgeInsetsZero];
- }
-
- NSInteger tag = 0;
- CGFloat h,x,w,y;
-
- //placeHolder
- UIView* vi = [[UIView alloc] initWithFrame:kFrame];
- [self.view addSubview:vi];
- [vi setBackgroundColor:backGroundColor];
- vi.hidden = YES;
- placeHolder = vi;
-
- w = h = kSize.width/3.0;
- x = y = w;
- UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [iv setImage:[UIImage imageNamed:@"community4.png"]];
- [iv setContentMode:UIViewContentModeScaleAspectFit];
- [placeHolder addSubview:iv];
-
- y += h + 20;
- x = 0;
- w = kSize.width;
- h = 40;
- UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [label setText:@"学车记忆宝贵,为何不留下点什么~"];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setTextColor:contentTextColor];
- [placeHolder addSubview:label];
-
- //tabbar
- h = 60;
- UIView* bar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - kNavOffSet -kSafeAreaBottomHeight-h, kSize.width, h )];
- [bar setBackgroundColor:backGroundColor];
- [bar addSelfViewWithRect:CGRectMake(0, 0, kSize.width, 1) Color:KlineColor];
- [self.view addSubview:bar];
-
- w = 100;
- x = (kSize.width - w)/2.0;
- STButton* stBtn = [[STButton alloc] initWithFrame:CGRectMake(x, 0, w, h)];
- [stBtn setImage:[UIImage imageNamed:@"community2.png"] withTitle:@"发布话题" Font:SmallFont forState:UIControlStateNormal];
- [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [stBtn setStyle:1];
- [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [bar addSubview:stBtn];
- [stBtn setTag:tag++];
- }
- -(void)btnClick:(UIButton*)sender
- {
- PostTopicVC* vc = [[PostTopicVC alloc] init];
- vc.type = @"1";
- [self navPushHideTabbarToVC:vc];
- }
- #pragma mark -
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 30;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 1;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- NSDictionary* obj = models[section];
- UILabel* v = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 30)];
- [v setText:obj[@"TI_CRDATE"]];
- [v setTextColor:defGreen];
- [v setFont:[UIFont scaleSize:12]];
- // setRandomColor(v);
- return v;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return communityCellHeight(models[indexPath.section] , 2);
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 1;
- //return models.count;
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return models.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CommunityCell* cell = [CommunityCell cellForTableView:tableView Style:2];
- //用于通知VC跳转到评论
- [cell setBackgroundColor:[UIColor whiteColor]];
- cell.layer.cornerRadius = 5;
- cell.layer.masksToBounds = YES;
- [cell setDelegate:self];
- [cell setModel:models[indexPath.section]];
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary* obj = models[indexPath.section];
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- TopicVC* vc = [[TopicVC alloc] init];
- vc.topicId = obj[@"ID"];
- [self navPushHideTabbarToVC:vc];
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)])
- {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([cell respondsToSelector:@selector(setLayoutMargins:)])
- {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
- CGPoint off = scrollView.contentOffset;
- if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
- [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
- [self getTopicByUser];
- }
- }
- #pragma mark - 数据请求
- /**对某一话题进行评论
- */
- -(void)gotoComment:(NSString *)comId
- {
- if (!myDelegate.isLogin) {
- return;
- }
- TopicVC* vc = [[TopicVC alloc] init];
- [vc setTopicId:comId];
- [vc setTextViewActive:YES];
- [self navPushHideTabbarToVC:vc];
- }
- /**下载的json里面没有头像地址。
- */
- -(void)getTopicByUser
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
- if(!_userID){
- _userID = defUser.userDict[@"id"];
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"user" Value:_userID];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"10"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
-
- NSString* method = @"getTopicByUser";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
-
- [MBProgressHUD hideHUDForView:self.view];
- if (models.count == 0) {
- placeHolder.hidden = NO;
- }else{
- placeHolder.hidden = YES;
- }
-
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
-
- NSArray* json = dict[@"body"];
- if (json.count < 1) {
- ShowMsg(@"已加载全部");
- return;
- }
-
- if (currentPage == 1) {
- [models removeAllObjects];
- [models addObjectsFromArray:json];
- placeHolder.hidden = YES;
- [myTableView reloadData];
- }else{
- [models addObjectsFromArray:json];
- placeHolder.hidden = YES;
- [myTableView reloadData];
- }
- currentPage ++;
- }];
- }
- @end
|