Chat interface


Hq88ClubGlobal *gb;

@interface Hq88MessageDetailViewController ()


@end


@implementation Hq88MessageDetailViewController

@synthesize topImageStr,topTitleStr,topTimeStr,letterId,trueName,getOrSet,isRead,sendArray,allArray,sendParser,cellItem,cellParser,isTeacher,topUserId;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}

- (void)viewDidUnload {

    topBarImageView = nil;

}



- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    //背景图片

     appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

    self.view.backgroundColor = RGB(248, 248, 248);

    UIImage *topImage = [UIImage imageNamed:@"bg_top_nav.png"];

    topBarImageView = [[UIImageView alloc] initWithImage:topImage];

    [topBarImageView setFrame:CGRectMake(0, 0,topImage.size.width/2,topImage.size.height/2)];

    topBarImageView.userInteractionEnabled = YES;

    [self.view addSubview:topBarImageView];

    [topBarImageView release];

    

    //顶部标题

    UILabel *titleLable =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, topImage.size.width/2, topImage.size.height/2)];

    titleLable.text = @"消息详情";;

    titleLable.textAlignment =UITextAlignmentCenter;

    titleLable.backgroundColor =[UIColor clearColor];

    titleLable.font =[UIFont systemFontOfSize:25];

    titleLable.textColor =[UIColor whiteColor];

    [topBarImageView addSubview:titleLable];

    [titleLable release];

    

    //   返回

    UIImage *backImage = [UIImage imageNamed:@"bg_forget_cancel.png"];

    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];

    backButton.frame = CGRectMake(5, (topBarImageView.frame.size.height - backImage.size.height/2)/2 , backImage.size.width/2, backImage.size.height/2);

    backButton.backgroundColor = [UIColor clearColor];

    backButton.userInteractionEnabled = YES;

    [backButton setTitle:@"返回" forState:UIControlStateNormal];

    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];

    [backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];

    [topBarImageView addSubview:backButton];

     

    topTimeStr =[topTimeStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    topTimeStr =[topTimeStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

    topTimeStr =[topTimeStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    topTitleStr =[topTitleStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    topTitleStr =[topTitleStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

    topTitleStr =[topTitleStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    topTitleStr =[topTitleStr stringByReplacingOccurrencesOfString:@" " withString:@""];

    CGSize nameSize =[trueName sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(MainWidth-60-[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, MainHeight-topBarImageView.frame.size.height) lineBreakMode:UILineBreakModeWordWrap];

    

   

    


    NSLog(@"appDelegate.loginViewController.loginXmlParser.userIDString=%d",[appDelegate.loginViewController.loginXmlParser.userIDString intValue]);

    NSLog(@"topUserId=%d",[topUserId intValue]);

    //顶部图片

        }

    

    //   点击图片事件

   

    //    输入背景和列表

   

    

    //输入框图片

    UIImageView *inPutView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg_hDetail_input.png"]];

    inPutView.frame =CGRectMake(15, speackBackView.frame.size.height/2-[UIImage imageNamed:@"bg_hDetail_input.png"].size.height/4-1, [UIImage imageNamed:@"bg_hDetail_input.png"].size.width/2, [UIImage imageNamed:@"bg_hDetail_input.png"].size.height/2);

    [speackBackView addSubview:inPutView];

    speackBackView.userInteractionEnabled =YES;

    inPutView.userInteractionEnabled =YES;

    [inPutView release];

    

    //输入框

   

    //切换表情按钮

    smileBtn =[self initWith:[UIImage imageNamed:@"bg_myCourseDetail_smile.png"] title:nil titleColor:nil btnFont:nil];

    UIButton *smileBackBtn =[self initWith:nil title:nil titleColor:nil btnFont:nil];

    smileBtn.frame =CGRectMake(speackBackView.frame.size.width/2+inPutView.frame.size.width/2+inPutView.frame.origin.x/2-[UIImage imageNamed:@"bg_myCourseDetail_smile.png"].size.width/4, speackBackView.frame.size.height/2-[UIImage imageNamed:@"bg_myCourseDetail_smile.png"].size.height/4, [UIImage imageNamed:@"bg_myCourseDetail_smile.png"].size.width/2, [UIImage imageNamed:@"bg_myCourseDetail_smile.png"].size.height/2);

    smileBackBtn.frame =CGRectMake(smileBtn.frame.origin.x-3, smileBtn.frame.origin.y-3, smileBtn.frame.size.width+20, smileBtn.frame.size.height+10);

    [smileBackBtn addTarget:self action:@selector(smileAction) forControlEvents:UIControlEventTouchUpInside];

    [smileBtn addTarget:self action:@selector(smileAction) forControlEvents:UIControlEventTouchUpInside];

    [speackBackView addSubview:smileBtn];

    [speackBackView addSubview:smileBackBtn];

    selectTag =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg_myCourseDetail_smile.png"]];

    selectKeyBoardNum =1;

    faceBoard = [[FaceBoard alloc] init];

    faceBoard.backgroundColor = [UIColor clearColor];

    faceBoard.delegate = self;

    faceBoard.frame =CGRectMake(faceBoard.frame.origin.x, MainHeight, faceBoard.frame.size.width, faceBoard.frame.size.height);

    [self.view addSubview:faceBoard];

    currentPage =1;

    [self cellPleaseParser];

}

//点击图片事件

-(void)iconSelectAction

{

    if ([topUserId intValue] == [appDelegate.loginViewController.loginXmlParser.userIDString intValue]) {

        Hq88PersonalInformationViewController *personalInfor = [[Hq88PersonalInformationViewController alloc]init];

        [self.navigationController pushViewController:personalInfor animated:YES];

        [personalInfor release];

    }

    else {

        Hq88FrindDetailViewController *frendlyVc = [[Hq88FrindDetailViewController alloc]init];

        frendlyVc.detailUserIdString = topUserId;

        frendlyVc.detailPhotoPathString = topImageStr;

        frendlyVc.detailTrueNameString = trueName;

        frendlyVc.detailUserTypeString = [NSString stringWithFormat:@"%d",[isTeacher intValue]+1];

        [self.navigationController pushViewController:frendlyVc animated:YES];

        [frendlyVc release];

    }

}

//更多数据

-(void)moreClassButtonAction

{

    currentPage ++;

    [self cellParsers];

}

#pragma mark setButton

-(UIButton*)initWith:(UIImage*)backgroundImage title:(NSString*)title titleColor:(UIColor*)titleColor btnFont:(UIFont*)btnFont

{

    UIButton *getButton =[UIButton buttonWithType:UIButtonTypeCustom];

    [getButton setBackgroundImage:backgroundImage forState:UIControlStateNormal];

    [getButton setTitle:title forState:UIControlStateNormal];

    [getButton setTitleColor:titleColor forState:UIControlStateNormal];

    getButton.titleLabel.font =btnFont;

    return  getButton;

}


//点击旁边取消键盘响应

-(void)clearButtonAction

{

    [UIView beginAnimations:nil context:nil];

    inputeField.userInteractionEnabled =YES;

    [UIView setAnimationDuration:0.25];

    selectKeyBoardNum =1;

    faceBoard.frame =CGRectMake(faceBoard.frame.origin.x, MainHeight, faceBoard.frame.size.width, faceBoard.frame.size.height);

    speackBackView.frame =CGRectMake(speackBackView.frame.origin.x, MainHeight-[UIImage imageNamed:@"bg_myCourseDetail_bottomBack.png"].size.height/2, speackBackView.frame.size.width, speackBackView.frame.size.height);

       backView.hidden =YES;

    [inputeField resignFirstResponder];

    [UIView commitAnimations];

}


//表情按钮

-(void)smileAction

{

    if (selectTag.image ==[UIImage imageNamed:@"bg_myCourseDetail_smile.png"]) {

        [smileBtn setBackgroundImage:[UIImage imageNamed:@"bg_publish_keyboard.png"] forState:UIControlStateNormal];

        [selectTag setImage:[UIImage imageNamed:@"bg_publish_keyboard.png"]];

        [inputeField resignFirstResponder];

        inputeField.userInteractionEnabled =NO;

        if (selectKeyBoardNum ==1) {

            inputeField.userInteractionEnabled =YES;

            [inputeField becomeFirstResponder];

        }

    }

    else {

        inputeField.userInteractionEnabled =YES;

        [smileBtn setBackgroundImage:[UIImage imageNamed:@"bg_myCourseDetail_smile.png"] forState:UIControlStateNormal];

        [selectTag setImage:[UIImage imageNamed:@"bg_myCourseDetail_smile.png"]];

        [inputeField becomeFirstResponder];

    }

}


//表格数据解析

-(void)cellPleaseParser

{

   

    NSString *userIdString = appDelegate.loginViewController.loginXmlParser.userIDString;

    NSString *ticket =appDelegate.loginViewController.loginXmlParser.ticketString;

    NSString *urlStr =[NSString stringWithFormat:Hq88Club_message_detail_cell_please_Url,userIdString,ticket,letterId,isRead];

    urlStr =[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSURL *url =[NSURL URLWithString:urlStr];

    NSURLRequest *request =[NSURLRequest requestWithURL:url];

    NSData *daten =[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

    HQ88ClubMessageDetailCellPleaseXmlParser *pleaseParser=[[HQ88ClubMessageDetailCellPleaseXmlParser alloc]initWithData:daten];

    if ([pleaseParser.status intValue]==1000) {

        progressHud = [[MBProgressHUD alloc] initWithView:self.navigationController.view];

        [self.navigationController.view addSubview:progressHud];

        progressHud.labelText = @"加载中...";

        [progressHud showWhileExecuting:@selector(cellParsers) onTarget:self withObject:nil animated:YES];

    }

    else {

        PAAlertView *alertView =[[PAAlertView alloc]initWithFistButton:@"确定" SencodButton:nil Message:pleaseParser.messageStr Delegate:self];

        alertView.tag =100001;

        [alertView performSelectorOnMainThread:@selector(show)

                                        withObject:nil

                                     waitUntilDone:YES];

        [alertView release];

    }

    [pleaseParser release];

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    inputeField.text =[inputeField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    inputeField.text =[inputeField.text stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    inputeField.text =[inputeField.text stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    inputeField.text =[inputeField.text stringByReplacingOccurrencesOfString:@" " withString:@""];

    if ([inputeField.text length]==0||inputeField.text ==nil) {

        PAAlertView *alertView =[[PAAlertView alloc]initWithFistButton:@"确定" SencodButton:nil Message:@"发送内容不能为空" Delegate:self];

        [alertView performSelectorOnMainThread:@selector(show)

                                    withObject:nil

                                 waitUntilDone:YES];

        [alertView release];

        return NO;

    }

    else {

        [UIView beginAnimations:nil context:nil];

        [UIView setAnimationDuration:0.25];

        speackBackView.frame =CGRectMake(speackBackView.frame.origin.x, MainHeight-[UIImage imageNamed:@"bg_myCourseDetail_bottomBack.png"].size.height/2+4, speackBackView.frame.size.width, speackBackView.frame.size.height);

        faceBoard.frame =CGRectMake(faceBoard.frame.origin.x, MainHeight, faceBoard.frame.size.width, faceBoard.frame.size.height);

        [UIView commitAnimations];

        [inputeField resignFirstResponder];

        selectKeyBoardNum =1;

        [self sendMessage];

        return YES;

    }

}


//发送消息解析

-(void)sendMessage

{

    progressHud = [[MBProgressHUD alloc] initWithView:self.navigationController.view];

    [self.navigationController.view addSubview:progressHud];

    progressHud.labelText = @"加载中...";

    [progressHud showWhileExecuting:@selector(sendSmile) onTarget:self withObject:nil animated:YES];

}

-(void)sendSmile

{

    sendArray =[[NSMutableArray alloc]init];

    NSString *userIdString = appDelegate.loginViewController.loginXmlParser.userIDString;

    NSString *ticket =appDelegate.loginViewController.loginXmlParser.ticketString;

    NSString *userName =appDelegate.loginViewController.loginXmlParser.trueNameString;

    NSString *userIcon =appDelegate.loginViewController.loginXmlParser.iconURLString;

    NSString *urlStr =[NSString stringWithFormat:Hq88Club_message_detail_answer_Url,userIdString,ticket,letterId, [gb toURLUTF8String: userName ],[gb toURLUTF8String:inputeField.text]];

    

    urlStr =[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSURL *url =[NSURL URLWithString:urlStr];

    NSURLRequest *request =[NSURLRequest requestWithURL:url];

    NSData *daten =[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

    sendParser =[[HQ88ClubMessageDetailSendXmlParser alloc]initWithData:daten];

    //解析数据判断

    if ([sendParser.status intValue]==1000) {

        NSDate *dates = [NSDate date];

        NSDateFormatter *formatter =  [[NSDateFormatter alloc] init];

        [formatter setDateFormat:@"今天 HH:mm"];

        NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/beijing"];

        [formatter setTimeZone:timeZone];

        NSString *loctime = [formatter stringFromDate:dates];

        cellItem =[[HQ88ClubMessageDetailCellItem alloc]init];

        cellItem.trueName =userName;

        cellItem.photoPath =userIcon;

        cellItem.cellUserId = appDelegate.loginViewController.loginXmlParser.userIDString;

        cellItem.content = inputeField.text;

        cellItem.createTime =loctime;

        [sendArray addObject:cellItem];

        [allArray addObjectsFromArray:sendArray];

        [speckTableView reloadData];

        NSIndexPath *idxPath = [NSIndexPath indexPathForRow:[allArray count]-1 inSection:0];

        [speckTableView scrollToRowAtIndexPath:idxPath atScrollPosition:UITableViewScrollPositionNone animated:NO];

        inputeField.text =nil;

        [formatter release];

        [self addEgoView];

    }

    else {

        if ([sendParser.message length] ==0) {

            PAAlertView *alertView =[[PAAlertView alloc]initWithFistButton:@"确定" SencodButton:nil Message:@"当前服务器繁忙,请稍后重试!" Delegate:self];

            [alertView performSelectorOnMainThread:@selector(show)

                                        withObject:nil

                                     waitUntilDone:YES];

            [alertView release];

        }

        else {

            PAAlertView *alertView =[[PAAlertView alloc]initWithFistButton:@"确定" SencodButton:nil Message:sendParser.message Delegate:self];

            [alertView performSelectorOnMainThread:@selector(show)

                                        withObject:nil

                                     waitUntilDone:YES];

            [alertView release];

        }

    }

       backView.hidden =YES;

}

//列表解析

-(void)cellParsers

{

    NSString *userIdString = appDelegate.loginViewController.loginXmlParser.userIDString;

    NSString *ticket =appDelegate.loginViewController.loginXmlParser.ticketString;

    NSString *current =[NSString stringWithFormat:@"%d",currentPage];

    NSString *urlStr =[NSString stringWithFormat:Hq88Club_message_detail_cell_Url,userIdString,ticket,current,letterId];

    urlStr =[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSURL *url =[NSURL URLWithString:urlStr];

    NSURLRequest *request =[NSURLRequest requestWithURL:url];

    NSData *daten =[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

    cellParser =[[HQ88ClubMessageDetailCellXmlParser alloc]initWithData:daten];

    [allArray addObjectsFromArray:cellParser.allArray];

    if (currentPage >[cellParser.totalPage intValue]) {

        PAAlertView *alertView =[[PAAlertView alloc]initWithFistButton:@"确定" SencodButton:nil Message:@"已经是最后一页了" Delegate:self];

        alertView.tag =100001;

        [alertView performSelectorOnMainThread:@selector(show)

                                    withObject:nil

                                 waitUntilDone:YES];

        [alertView release];

    }

    if (currentPage ==1) {

        if ([cellParser.allArray count]==0) {

        }

    }

    if ([cellParser.status intValue] ==1000) {

        if ([cellParser.allArray count]>0) {

            if (currentPage <=[cellParser.totalPage intValue]) {

                [speckTableView reloadData];

                NSIndexPath *idxPath = [NSIndexPath indexPathForRow:[allArray count]-1 inSection:0];

                [speckTableView scrollToRowAtIndexPath:idxPath atScrollPosition:UITableViewScrollPositionNone animated:NO];

            }

        }

    }

    else {

        if ([cellParser.message length] ==0) {

            PAAlertView *alertView =[[PAAlertView alloc]initWithFistButton:@"确定" SencodButton:nil Message:@"当前服务器繁忙,请稍后重试!" Delegate:self];

            [alertView performSelectorOnMainThread:@selector(show)

                                        withObject:nil

                                     waitUntilDone:YES];

            [alertView release];

        }

        else {

            PAAlertView *alertView =[[PAAlertView alloc]initWithFistButton:@"确定" SencodButton:nil Message:cellParser.message Delegate:self];

            [alertView performSelectorOnMainThread:@selector(show)

                                        withObject:nil

                                     waitUntilDone:YES];

            [alertView release];

        }

    }

    [self addEgoView];

}


#pragma mark UITableView delegat

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

        return [allArray count];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    cellItem =[allArray objectAtIndex:[indexPath row]];

    NSString *contentStr =[cellItem.content  stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    contentStr =[contentStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    contentStr =[contentStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

    contentStr =[contentStr stringByReplacingOccurrencesOfString:@" " withString:@""];

    UIView *getHeightView =[self assembleMessageAtIndex:contentStr];

    return  getHeightView.frame.size.height+90;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *identifier = @"etuancell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (!cell) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

        

        [cell setAccessoryType:UITableViewCellAccessoryNone];

        // 取消选择模式

                       cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }else{

        // 删除cell中的子对象,刷新覆盖问题。

        while ([cell.contentView.subviews lastObject] != nil) {

            [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];

        }

    }

    UIFont *font =[UIFont systemFontOfSize:14];

    cellItem =[allArray objectAtIndex:[indexPath row]];

    NSString *contentStr =[cellItem.content  stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    contentStr =[contentStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    contentStr =[contentStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

    contentStr =[contentStr stringByReplacingOccurrencesOfString:@" " withString:@""];

    

    CGSize size =[contentStr sizeWithFont:font constrainedToSize:CGSizeMake(MainWidth-60-[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, MainHeight-topBarImageView.frame.size.height) lineBreakMode:UILineBreakModeWordWrap];

    NSString *timetStr =[cellItem.createTime stringByReplacingOccurrencesOfString:@" " withString:@""];

    timetStr =[timetStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    timetStr =[timetStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    timetStr =[timetStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

    

    //时间

    UILabel *timeLable =[[UILabel alloc]initWithFrame:CGRectMake(0, 10, MainWidth, 20)];

    timeLable.textAlignment =UITextAlignmentCenter;

    timeLable.text =timetStr;

    timeLable.backgroundColor =[UIColor clearColor];

    timeLable.font =[UIFont systemFontOfSize:14];

    [cell.contentView addSubview:timeLable];

    [timeLable release];

    

    //图片和内容

    UIImageView *cellIcon =[[UIImageView alloc]init];

    UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    NSString *iconStr =[cellItem.photoPath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    iconStr =[iconStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    iconStr =[iconStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

    iconStr =[iconStr stringByReplacingOccurrencesOfString:@" " withString:@""];

    [cellIcon setImageWithURL:[NSURL URLWithString:iconStr] placeholderImage:[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"]];

    UIView *returnView =[self assembleMessageAtIndex:contentStr];

    NSString *userName =appDelegate.loginViewController.loginXmlParser.trueNameString;

    UIImageView *contentBackView =[[UIImageView alloc]init];

    [iconBtn setImage:nil forState:UIControlStateNormal];

    NSString *trueNameStr =[cellItem.trueName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    trueNameStr =[trueNameStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];

    trueNameStr =[trueNameStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

    trueNameStr =[trueNameStr stringByReplacingOccurrencesOfString:@" " withString:@""];

    UILabel *nameLable =[[UILabel alloc]initWithFrame:CGRectMake(15, 15, 200, 15)];

    nameLable.backgroundColor =[UIColor clearColor];

    nameLable.font =[UIFont systemFontOfSize:14];

//    [contentBackView addSubview:nameLable];

//    [nameLable release];

    CGSize nameSize =[trueNameStr sizeWithFont:font constrainedToSize:CGSizeMake(MainWidth-60-[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, MainHeight-topBarImageView.frame.size.height) lineBreakMode:UILineBreakModeWordWrap];

    if ([trueNameStr isEqualToString:userName]) {

        nameLable.text =[NSString stringWithFormat:@":"];

        contentBackView.image =[[UIImage imageNamed:@"bg_messageDetail_inputRight_img.png" ]stretchableImageWithLeftCapWidth:6 topCapHeight:19];

        cellIcon.frame =CGRectMake(cell.frame.size.width-[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2-10, timeLable.frame.origin.y+timeLable.frame.size.height+7, [UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, [UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.height/2);

        contentStr =[contentStr stringByReplacingOccurrencesOfString:@"[/" withString:@""];

        contentStr =[contentStr stringByReplacingOccurrencesOfString:@"]" withString:@""];

        size =[contentStr sizeWithFont:font constrainedToSize:CGSizeMake(MainWidth-60-[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, MainHeight-topBarImageView.frame.size.height) lineBreakMode:UILineBreakModeWordWrap];

        returnView.frame =CGRectMake(15,18,returnView.frame.size.width,returnView.frame.size.height);

        contentBackView.frame =CGRectMake(MainWidth-returnView.frame.size.width-20-cellIcon.frame.size.width-24, cellIcon.frame.origin.y,returnView.frame.size.width+31, returnView.frame.size.height+50);

        nameSize =[nameLable.text sizeWithFont:font constrainedToSize:CGSizeMake(MainWidth-60-[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, MainHeight-topBarImageView.frame.size.height) lineBreakMode:UILineBreakModeWordWrap];

        if (returnView.frame.size.width >170) {

            contentBackView.frame =CGRectMake(MainWidth-size.width-30-cellIcon.frame.size.width-24, cellIcon.frame.origin.y, 250, returnView.frame.size.height+50);

        }

        if (returnView.frame.size.height <18) {

            contentBackView.frame =CGRectMake(MainWidth-returnView.frame.size.width-20-cellIcon.frame.size.width-27, contentBackView.frame.origin.y, returnView.frame.size.width+32, returnView.frame.size.height+50);

        }

    }

    else {

        nameLable.text =[NSString stringWithFormat:@"%@:",trueNameStr];

        contentStr =[contentStr stringByReplacingOccurrencesOfString:@"[/" withString:@""];

        contentStr =[contentStr stringByReplacingOccurrencesOfString:@"]" withString:@""];

        size =[contentStr sizeWithFont:font constrainedToSize:CGSizeMake(MainWidth-60-[UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, MainHeight-topBarImageView.frame.size.height) lineBreakMode:UILineBreakModeWordWrap];

        contentBackView.image =[[UIImage imageNamed:@"bg_messageDetail_inputLeft_img.png" ]stretchableImageWithLeftCapWidth:12 topCapHeight:19];

        cellIcon.frame =CGRectMake(10, timeLable.frame.origin.y+timeLable.frame.size.height+7, [UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.width/2, [UIImage imageNamed:@"bg_messageDetail_speackIcon.png"].size.height/2);

        returnView.frame =CGRectMake(23, 18,returnView.frame.size.width,returnView.frame.size.height);

        contentBackView.frame =CGRectMake(cellIcon.frame.origin.x+cellIcon.frame.size.width+5, cellIcon.frame.origin.y,returnView.frame.size.width+41, returnView.frame.size.height+50);

        if (returnView.frame.size.width >170) {

            contentBackView.frame =CGRectMake(cellIcon.frame.origin.x+cellIcon.frame.size.width+5, cellIcon.frame.origin.y, 250,returnView.frame.size.height+50);

        }

        if (returnView.frame.size.height <30) {

            contentBackView.frame =CGRectMake(cellIcon.frame.origin.x+cellIcon.frame.size.width+5, contentBackView.frame.origin.y, returnView.frame.size.width+43, returnView.frame.size.height+50);

        }

    }

    cellIcon.layer.cornerRadius = 6;

    cellIcon.layer.masksToBounds = YES;

    [cell.contentView addSubview:cellIcon];

    


    [cell.contentView addSubview:contentBackView];

    [contentBackView addSubview:returnView];

    [returnView release];

    [cellIcon release];

    [contentBackView release];

    if ([cellItem.isTeacher intValue]==1) {

        UIImageView *cellIconCover = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ico_teacher.png"]];

        cellIconCover.frame = CGRectMake(cellIcon.frame.size.width-[UIImage imageNamed:@"ico_teacher.png"].size.width,cellIcon.frame.size.height-[UIImage imageNamed:@"ico_teacher.png"].size.height , [UIImage imageNamed:@"ico_teacher.png"].size.width, [UIImage imageNamed:@"ico_teacher.png"].size.height);

        [cellIcon addSubview:cellIconCover];

        [cellIconCover release];

    }

    iconBtn.frame = CGRectMake(cellIcon.frame.origin.x, cellIcon.frame.origin.y, cellIcon.frame.size.width, cellIcon.frame.size.height);

    iconBtn.tag =[indexPath row];

    [iconBtn addTarget:self action:@selector(personalAction:) forControlEvents:UIControlEventTouchUpInside];

    [cell.contentView addSubview:iconBtn];

    return cell;

}

-(void)personalAction :(id)userIdBtn

{

    UIButton *Btn =(UIButton*)userIdBtn;

       cellItem =[allArray objectAtIndex:Btn.tag];

    NSLog(@"cellUserId=%@",cellItem.cellUserId);

    NSLog(@"appDelegate.loginViewController.loginXmlParser.userIDString=%@",appDelegate.loginViewController.loginXmlParser.userIDString);

    if ([cellItem.cellUserId intValue] ==[appDelegate.loginViewController.loginXmlParser.userIDString intValue]) {

        Hq88PersonalInformationViewController *personVc = [[Hq88PersonalInformationViewController alloc]init];

        [self.navigationController pushViewController:personVc animated:YES];

        [personVc release];

    }

    else {

        

        Hq88FrindDetailViewController *frendVc = [[Hq88FrindDetailViewController alloc]init];

        frendVc.detailUserIdString = cellItem.cellUserId;

        frendVc.detailPhotoPathString = cellItem.photoPath;

        frendVc.detailTrueNameString = cellItem.trueName;

        frendVc.detailUserTypeString = [NSString stringWithFormat:@"%d",[cellItem.isTeacher intValue]+1];

        [self.navigationController pushViewController:frendVc animated:YES];

        [frendVc release];

    }

}


//输出表情

-(UIView *)assembleMessageAtIndex : (NSString *) message {

    NSMutableArray *array =[[NSMutableArray alloc]init];

    [self getImageRange:message :array ];

    NSArray *data =array;

    UIView *returnView = [[UIView alloc] initWithFrame:CGRectZero];

    UIFont *fon = [UIFont systemFontOfSize:14.0f];

    CGFloat upX = 0;

    CGFloat upY = 0;

    CGFloat X = 0;

    CGFloat Y = 0;

    if (data) {

        for (int i=0;i < [data count];i++) {

            NSString *str=[data objectAtIndex:i];

            if ([str hasPrefix:@"[/"] && [str hasSuffix:@"]"])

            {

                if (upX >=200) {

                    upY = upY + 18;

                    upX = 0;

                    X = 200;

                    Y = upY;

                }

                NSString *imageName=[str substringWithRange:NSMakeRange(2, str.length - 3)];

                UIImageView *img=[[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];

                img.frame = CGRectMake(upX, upY, 18, 18);

                [returnView addSubview:img];

                [img release];

                upX=18+upX;

                if (X<200) {

                    X =upX;

                }

            }

            else {

                for (int j = 0; j < [str length]; j++) {

                    NSString *temp = [str substringWithRange:NSMakeRange(j, 1)];

                    if (upX >=200)

                    {

                        upY = upY + 18;

                        upX = 0;

                        X = 200;

                        Y =upY;

                    }

                    CGSize size=[temp sizeWithFont:fon constrainedToSize:CGSizeMake(1, 40)];

                    UILabel *la = [[UILabel alloc] initWithFrame:CGRectMake(upX,upY,size.width,size.height)];

                    la.font = fon;

                    la.text = temp;

                    la.backgroundColor = [UIColor clearColor];

                    [returnView addSubview:la];

                    [la release];

                    upX=upX+size.width;

                    if (X<200) {

                        X = upX;

                    }

                    

                }

            }

        }

    }

    returnView.frame =CGRectMake(0, 0, X, Y);

    return returnView;

}

-(void)getImageRange:(NSString*)message : (NSMutableArray*)array {

    NSRange range=[message rangeOfString: @"["];

    NSRange range1=[message rangeOfString: @"]"];

    if (range.length>0&&range1.length>0) {

        if (range.location>0) {

            [array addObject:[message substringToIndex:range.location]];

            [array addObject:[message substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)]];

            NSString *str=[message substringFromIndex:range1.location+1];

            [self getImageRange:str :array];

        }

        else {

            NSString *nextstr=[message substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)];

            if (![nextstr isEqualToString:@""]) {

                [array addObject:nextstr];

                NSString *str=[message substringFromIndex:range1.location+1];

                [self getImageRange:str :array];

            }else {

                return;

            }

        }

        

    } else if (message != nil) {

        [array addObject:message];

    }

}


#pragma mark-FaceBoardDelegate

-(void)setHq88TextView:(NSString *)textString

{

    NSMutableString *inputString=[[NSMutableString alloc]initWithString:inputeField.text];

    [inputString appendString:textString];

    inputeField.text = inputString;

    [inputString release];

}

-(void)deleteHq88TextView

{

    NSString *inputString= nil;

    if ([inputeField.text length]!=0) {

        inputString = inputeField.text;

    }

    NSString *string = nil;

    NSInteger stringLength = inputString.length;

    if (stringLength > 0) {

        if ([@"]" isEqualToString:[inputString substringFromIndex:stringLength-1]]) {

            if ([inputString rangeOfString:@"["].location == NSNotFound){

                string = [inputString substringToIndex:stringLength - 1];

            } else {

                string = [inputString substringToIndex:[inputString rangeOfString:@"[" options:NSBackwardsSearch].location];

            }

        } else {

            string = [inputString substringToIndex:stringLength - 1];

        }

    }

    inputeField.text = string;

}


#pragma mark UITextFieldDelegate

- (void)keyboardWillShow:(NSNotification *)notification

{

    //动画效果

    NSDictionary *userInfo = [notification userInfo];


    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardRect = [aValue CGRectValue];

    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

    NSTimeInterval animationDuration;

    [animationDurationValue getValue:&animationDuration];

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:animationDuration];

    faceBoard.frame =CGRectMake(faceBoard.frame.origin.x, MainHeight-keyboardRect.size.height, faceBoard.frame.size.width, faceBoard.frame.size.height);

    speackBackView.frame =CGRectMake(speackBackView.frame.origin.x,MainHeight-keyboardRect.size.height-[UIImage imageNamed:@"bg_myCourseDetail_bottomBack.png"].size.height/2, speackBackView.frame.size.width, speackBackView.frame.size.height);

       [UIView commitAnimations];

    if (selectTag.image ==[UIImage imageNamed:@"bg_publish_keyboard.png"]) {

        if (selectKeyBoardNum !=1) {

            inputeField.userInteractionEnabled =YES;

            faceBoard.hidden =NO;

        }

        else {

            inputeField.userInteractionEnabled =NO;

            [inputeField resignFirstResponder];

        }

    }

    backView.hidden =NO;

    selectKeyBoardNum+=1;

}


//返回按钮

- (void)backButtonAction{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"freshmessageViewController" object:nil];

    [self.navigationController popViewControllerAnimated:YES];

}

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

-(void)addEgoView{

    

    CGFloat height = speckTableView.contentSize.height;

    if (refreshFootView == nil) {

        if (height <speckTableView.frame.size.height) {

            EGORefreshTableFootView *view = [[EGORefreshTableFootView alloc] initWithFrame:CGRectMake(0.0f, speckTableView.frame.size.height, self.view.frame.size.width,speckTableView.bounds.size.height)];

            view.delegate = self;

            [speckTableView addSubview:view];

            refreshFootView = view;

            [view release];

        }

        else {

            EGORefreshTableFootView *view = [[EGORefreshTableFootView alloc] initWithFrame:CGRectMake(0.0f, height, self.view.frame.size.width,speckTableView.bounds.size.height)];

            view.delegate = self;

            [speckTableView addSubview:view];

            refreshFootView = view;

            [view release];

        }

    }else {

        height = speckTableView.contentSize.height;

        if (height <speckTableView.frame.size.height) {

            refreshFootView.frame = CGRectMake(0.0f, speckTableView.frame.size.height, self.view.frame.size.width, speckTableView.bounds.size.height);

        }

        else {

        refreshFootView.frame = CGRectMake(0.0f, height, self.view.frame.size.width, speckTableView.bounds.size.height);

        }

        

    }

    [refreshFootView refreshLastUpdatedDate];

    

}


#pragma mark -

#pragma mark Data Source Loading / Reloading Methods


- (void)reloadTableViewDataSource{

//  should be calling your tableviews data source model to reload

//  put here just for demo

reloading = YES;

}


- (void)doneLoadingTableViewData{

//  model should call this when its done loading

reloading = NO;

[refreshFootView egoRefreshScrollViewDataSourceDidFinishedLoading:speckTableView];

    [self moreClassButtonAction];

   CGFloat height = speckTableView.contentSize.height;

    if (height <speckTableView.frame.size.height) {

        refreshFootView.frame = CGRectMake(0.0f, speckTableView.frame.size.height, self.view.frame.size.width, speckTableView.bounds.size.height);

    }

    else {

    refreshFootView.frame = CGRectMake(0.0f, height, self.view.frame.size.width, speckTableView.bounds.size.height);

    }

}



#pragma mark -

#pragma mark UIScrollViewDelegate Methods


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    if (scrollView.contentOffset.y > 50  && reloading ==NO) {

        

        [refreshFootView egoRefreshScrollViewDidScroll:scrollView];

    }

    

}


- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

    [self addEgoView];

    

    if (scrollView.contentOffset.y > 50  && reloading ==NO) {

        

        [refreshFootView egoRefreshScrollViewDidEndDragging:scrollView];

        

    }

}



#pragma mark -

#pragma mark EGORefreshTableHeaderDelegate Methods


- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{

[self reloadTableViewDataSource];

[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:2.0];

}


- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{

return reloading; // should return if data source model is reloading

}


- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{

return [NSDate date]; // should return date data source was last changed

}

#pragma mark -

#pragma mark EGORefreshTableFootDelegate Methods


- (void)egoRefreshTableFootDidTriggerRefresh:(EGORefreshTableFootView*)view{

[self reloadTableViewDataSource];

    

    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0];

    

}


- (BOOL)egoRefreshTableFootDataSourceIsLoading:(EGORefreshTableFootView*)view{

    

    return reloading; // should return if data source model is reloading

}


- (NSDate*)egoRefreshTableFootDataSourceLastUpdated:(EGORefreshTableFootView*)view{

return [NSDate date]; // should return date data source was last changed

}

-(void)viewWillAppear:(BOOL)animated

{

    CustomTabBarController *tabBarController = (CustomTabBarController *)self.tabBarController;

    if (isIPhone5) {

        [tabBarController.view setFrame:(CGRect){0, 0, MainWidth, MainHeight+88}];

    }else{

        [tabBarController.view setFrame:(CGRect){0, 0, MainWidth, MainHeight}];

    }

    [self clearButtonAction];

}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值