对tableView的学习情况

 

这几天回来研究订火车票的苹果软件,我的目的就想在 “督导系统”的苹果端,做出一个搜索功能,类似于订火车票中的“列车时刻”中的查询,一个模糊查询,填写一个日期或一个课室地点或者一个节次就能够搜索出多条的信息,然后单击任何一条都可以进行查看,或者修改。

讲到这里,都可以想象得出来,需要3个窗口,问题就是如何将这三个窗体,用代码来连接?如何发送请求?如何将搜索到的结果,一条条列出来?

这几天的研究,我学到了:

1、搜索之前,必须判断需要填写的文本框,是否为空,若是,则提示用户“需要必须填写”。

if ([fromStationField.text length] == 0) {

UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"错误" 

message:@"出发站不能为空,请重新输入。" 

delegate:self 

cancelButtonTitle:@"确定" 

otherButtonTitlesnil];

[alert show];

[alert release];

return;

}//先判断输入框里是否有数据,如果是空就会报错

2、在火车票中先用GBK编码,再url编码,再发送请求:

//记录乘客填写的信息

MySingleton *mySingleton = [MySingleton sharedSingleton];

mySingleton.ticketNum = [ticketNumField.text intValue]; //类型转换,转换成int

mySingleton.fromStation =fromStationField.text;

mySingleton.toStation toStationField.text;

mySingleton.trainsn trainsnField.text;

mySingleton.travelDate travelDateField.text;

if ([seatTypeField.text isEqualToString:@"硬座"]) mySingleton.seatType 1;

else if ([seatTypeField.text isEqualToString:@"软座"]) mySingleton.seatType 2;

else if ([seatTypeField.text isEqualToString:@"硬卧"]) mySingleton.seatType 3;

else if ([seatTypeField.text isEqualToString:@"软卧"]) mySingleton.seatType 4;

else if ([seatTypeField.text isEqualToString:@"一等座"]) mySingleton.seatType 5;

else if ([seatTypeField.text isEqualToString:@"二等座"]) mySingleton.seatType 6;

mySingleton.seatTypeName seatTypeField.text;

NSString *fromstation = mySingleton.fromStation;

NSString *tostation = mySingleton.toStation;

NSString *traindate = mySingleton.travelDate;

NSString *checi = mySingleton.trainsn;

int traincount = mySingleton.ticketNum;

int seattype = mySingleton.seatType;

NSString * urlString = [NSString stringWithFormat:@"%@train_interface_ordersure.flow?",serverAddr];//server address

NSDate * nowDate = [NSDate date];

NSTimeInterval timeInterval = [nowDate timeIntervalSince1970];

NSString * timestamp = [NSString stringWithFormat:@"%f",timeInterval];

NSString * needToMd5String = [NSString stringWithFormat:@"%@%@%@",icpname,timestamp,key];

NSLog(@"%@",needToMd5String); 

NSString * authstring = [needToMd5String md5];

NSString * requestString = [NSString stringWithFormat:@"%@icpname=%@×tamp=%@&authstring=%@&traindate=%@&fromstation=%@&tostation=%@&checi=%@&traincount=%d&seattype=%d",

urlString,icpname,timestamp,authstring,traindate,fromstation,tostation,checi,traincount,seattype];

NSStringEncoding enc=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);

//先用GBK编码,再url编码 

requestString=[requestString stringByAddingPercentEscapesUsingEncoding:enc]; 

NSLog(@"requestString: %@", requestString);

NSMutableURLRequest *request = [[[NSMutableURLRequest allocinitautorelease];

[request setURL:[NSURL URLWithString:requestString]];        

[request setHTTPMethod:@"GET"];

[request setTimeoutInterval:20];

NSLog(@"%f",[request timeoutInterval]);

NSURLConnection *conn=[[NSURLConnection allocinitWithRequest:request delegate:self];

self.aConection = conn;

// [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timeOutFun) userInfo:nil repeats:NO];

if (conn)

{

receivedData = [[NSMutableData dataretain];

//[receivedData release];//注释掉便出错

}

3、我仍然找不到如何转换到搜索完之后,把结果show出来的窗口有关的代码;

4、创建数组,该数组中的元素将显示在表中,通过tableView:cellForRowAtIndexPath:方法,将数组中的元素设置到表的单元中。

5、表单元中直接放置了跳转对象画面的类名,tableView:didSelectRowUINavigationController 的pushViewController: animated:方法实现画面跳转。跳转到下一层画面后,将自动显示返回按钮。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值