首页 > 代码库 > 意见反馈

意见反馈

技术分享

 意见反馈


序言:

        现在APP开发都少不了用户意见反馈这一界面,随着,大多新手涌入社会这一行业,为此写出这一文档。

正文:

      意见反馈,无谓就是将用户的想法和建议,反馈到开发者这里,根据用户的反馈,做出相应的更改自己的软件。

第一步:

我们要添加3个协议。如下:

UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate

第二步:

我们创建3对象。如下:

    UITableView*_ZSJTableView;
    UITextField*_ZSJField;
    UIImageView*ZSJTOOLBackImageView;
第三步:

我们在创建2个可变的数组。或者一个,这里我们创建两个。如下;

@property(nonatomic,strong)NSMutableArray*_ZSJDataArray;
@property(nonatomic ,strong)NSMutableArray*TextFieldArr;

第四步:

我们首先布局头部显示的排布。如下;

 UIImageView*ZSJNavImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 20, SCREENWight, 44)];
    ZSJNavImageView.userInteractionEnabled=YES;
    ZSJNavImageView.backgroundColor=[UIColor colorWithRed:190.0/255.0 green:190.0/255.0 blue:190.0/255.0 alpha:1];
    
    UIButton*ReturnButton=[UIButton buttonWithType:UIButtonTypeCustom];
    ReturnButton.frame=CGRectMake(15, 10, 10, 25);
    [ReturnButton setImage:[UIImage imageNamed:@"Return.png"] forState:UIControlStateNormal];
    [ReturnButton addTarget:self action:@selector(ReturnClick) forControlEvents:UIControlEventTouchUpInside];
    [ZSJNavImageView addSubview:ReturnButton];

    
    UILabel*FeedBackLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREENWight/2-50, 2, 100, 40)];
    FeedBackLabel.text=@"意见反馈";
    FeedBackLabel.textColor=[UIColor blackColor];
    FeedBackLabel.textAlignment=NSTextAlignmentCenter;
    [ZSJNavImageView addSubview:FeedBackLabel];
    [self.view addSubview:ZSJNavImageView];

第五步:

 我们要创建聊天的主要工具,UItableView。如下:

 UIView*BackView=[[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREENWight, SCREENHight-50-64)];
    UIImageView*BackImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREENWight, BackView.frame.size.height)];
    BackImageView.image=[UIImage imageNamed:@"zsj.png"];//添加聊天背景。
    [BackView addSubview:BackImageView];
    
    _ZSJTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREENWight, BackView.frame.size.height) style:UITableViewStylePlain];
    _ZSJTableView.backgroundView=BackView;
    _ZSJTableView.dataSource=self;
    _ZSJTableView.delegate=self;
    _ZSJTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_ZSJTableView];
第六步:

我们实现UItableView的几个代理协议。如下:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self._ZSJDataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString*ZSJStr=[self._ZSJDataArray[indexPath.row]firstObject];
    CGFloat  ZSJHight=[ZSJStr boundingRectWithSize:CGSizeMake(200, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSAttachmentAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.height;
    return  ZSJHight+60;
    
    
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZSJMessageCell*cell=[tableView dequeueReusableCellWithIdentifier:@"ID"];
    if (!cell) {
        cell=[[ZSJMessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor clearColor];
    }
    
    NSArray*array=self._ZSJDataArray[indexPath.row];
    [cell configModel:array];
    
    return cell;
    
}

第七步:

我们要自定义Cell。如下:

1、创建几个对象。如下:

 //做
    UIImageView*LeftImageView;
    UIImageView*LeftButtonImageView;
    UILabel*LeftMessageLabel;
    //有
    UIImageView*RightImageView;
    UIImageView*RightButtonImageView;
    UILabel*RightMessageLabel;

2、我们要创建一个数据传入的方法。如下:

-(void)configModel:(NSArray*)array;
3、我们排布数据显示模式。

 LeftImageView=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 30, 30)];
    LeftImageView.image=[UIImage imageNamed:@"zsjView.png"];
    LeftImageView.layer.cornerRadius=15;
    LeftImageView.layer.masksToBounds=YES;
    [self.contentView addSubview:LeftImageView];
    
    //右边头像
    RightImageView=[[UIImageView alloc]initWithFrame:CGRectMake(ScreWight-35, 5, 30, 30)];
    RightImageView.image=[UIImage imageNamed:@"2.jpg"];
    RightImageView.layer.cornerRadius=15;
    RightImageView.layer.masksToBounds=YES;
    [self.contentView addSubview:RightImageView];
    
  
    
    //左边气泡
    LeftButtonImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    //处理拉伸图像
    UIImage*leftImage=[UIImage imageNamed:@"fcl_chat_others"];
    leftImage=[leftImage stretchableImageWithLeftCapWidth:20 topCapHeight:20];
    LeftButtonImageView.image=leftImage;
    [self.contentView addSubview:LeftButtonImageView];
    //左边文字的label
    LeftMessageLabel=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, 100, 30)];
    LeftMessageLabel.numberOfLines=0;
    LeftMessageLabel.font=[UIFont systemFontOfSize:16];
    [LeftButtonImageView addSubview:LeftMessageLabel];
    
    //右边
    RightButtonImageView=[[UIImageView alloc]initWithFrame:CGRectMake(200, 0, 100, 30)];
    UIImage*image=[UIImage imageNamed:@"fcl_chat_me"];
    image=[image stretchableImageWithLeftCapWidth:20 topCapHeight:20];
    RightButtonImageView.image=image;
    [self.contentView addSubview:RightButtonImageView];
    
    RightMessageLabel=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, 100, 30)];
    RightMessageLabel.numberOfLines=0;
    RightMessageLabel.font=[UIFont systemFontOfSize:16];
    [RightButtonImageView addSubview:RightMessageLabel];
    

4、初入数据的实现。

 CGSize size;
    NSString*str=[array firstObject];
    
    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
        //iOS7的方法
        size=[str boundingRectWithSize:CGSizeMake(200, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:16]} context:nil].size;
        
    }else{
        size=[str sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(200, 1000)];
        
        
    }
    
    //取出是自己发送还是对方发送
    if ([[array lastObject]isEqualToString:@"0"]) {
        //对方发送
        RightImageView.hidden=YES;
        RightButtonImageView.hidden=YES;
        LeftImageView.hidden=NO;
        LeftButtonImageView.hidden=NO;
        
        LeftButtonImageView.frame=CGRectMake(40, 5, size.width+10, size.height+15);
        LeftMessageLabel.frame=CGRectMake(10, 6, size.width-5, size.height);
        LeftMessageLabel.text=[array firstObject];
        
        
    }else{
        //自己发送
        LeftImageView.hidden=YES;
        LeftButtonImageView.hidden=YES;
        RightImageView.hidden=NO;
        RightButtonImageView.hidden=NO;
        
        RightButtonImageView.frame=CGRectMake(ScreWight-40-size.width-10-10, 10, size.width+25, size.height+15);
        RightMessageLabel.frame=CGRectMake(10, 6, size.width , size.height);
        RightMessageLabel.text=[array firstObject];
        
    }


第八步;

我们实现下面的数据输入实现框。如下:

ZSJTOOLBackImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, SCREENHight-50, SCREENWight, 50)];
    ZSJTOOLBackImageView.backgroundColor=[UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:1];
    ZSJTOOLBackImageView.userInteractionEnabled=YES;
    [self.view addSubview:ZSJTOOLBackImageView];
    
    UIImageView*TextFieldBackView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 8, SCREENWight-70-10, 36)];
    TextFieldBackView.userInteractionEnabled=YES;
    TextFieldBackView.layer.masksToBounds=YES;
    TextFieldBackView.layer.cornerRadius=6;
    TextFieldBackView.backgroundColor=[UIColor whiteColor];
    [ZSJTOOLBackImageView addSubview:TextFieldBackView];
    
    _ZSJField=[[UITextField alloc]initWithFrame:CGRectMake(5, 4, SCREENWight-70, 35)];
    _ZSJField.delegate=self;
    _ZSJField.returnKeyType=UIReturnKeySend;
     
    [TextFieldBackView addSubview:_ZSJField];
    
    
    UIButton*SeccseBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    SeccseBtn.frame=CGRectMake(SCREENWight-65, 6, 50, 46);
    [SeccseBtn setBackgroundImage:[UIImage imageNamed:@"send.png"] forState:UIControlStateNormal];
    [SeccseBtn setTitle:@"发送" forState:UIControlStateNormal];
    [SeccseBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [SeccseBtn addTarget:self action:@selector(SDClick:) forControlEvents:UIControlEventTouchUpInside];
    [SeccseBtn sizeToFit];
    [ZSJTOOLBackImageView addSubview:SeccseBtn];
    
    

第九步;

 我们要实现发送代理和方法。如下:

 if (_ZSJField.text.length>0) {
        
        [self.TextFieldArr addObject:_ZSJField.text];
        [self XieRuField];
        NSLog(@"%@",self.TextFieldArr);
        [self._ZSJDataArray addObject:@[_ZSJField.text,@"1"]];
        [_ZSJTableView reloadData];
        [_ZSJTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self._ZSJDataArray.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        _ZSJField.text=nil;
        [self  performSelector:@selector(BackMessage) withObject:nil afterDelay:1];
    }
    

第十步:

我们要实现键盘的收藏。如下;

 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(showKeyBoard:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hideKeyBoard:) name:UIKeyboardWillHideNotification object:nil];
    

效果展示:

技术分享 技术分享技术分享




完整代码下载:

http://download.csdn.net/download/zhoushuangjian511/8352801







意见反馈