ios 点餐系统
这个程序的主要界面就是一个TabBarController。总共三个标签,第一个是所有的可点的菜,第二个是已点的菜,第三个是可以留言或者查看所有留言。
下面是第一个页面:

右上角的i按钮是添加新菜,每个cell中的order就是点餐咯,可以重复按多次。
首先说下这个列表的数据是存放在coredata中的,这个项目的coredata有两个实体,一个是dishes保存每一道菜的名字,id,价格,描述,菜系等。还有一个实体是type保存菜系。
这个项目用coredata的方式,正好是我想学的。
就是在新建项目的时候勾选use coredata,那么在appdelegate中就会出现与coredata响应的代码了,只需要根据自己的需要稍微修改即可。或者是自己在已有的项目中添加一个coredata文件,然后将一个已经勾选了use coredata的项目中的appdelagate中的一些代码复制过来即可。
那么在各个文件中我需要用到coredata的时候 要怎么操作呢?看下面的代码:
- HotelAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
- //connection
- NSManagedObjectContext *context = [appDelegate managedObjectContext];
- //table
- NSEntityDescription *entityDescr =[NSEntityDescription entityForName:@"Dishes" inManagedObjectContext:context];
- //query
- NSFetchRequest *request = [[NSFetchRequest alloc] init];
- [request setEntity:entityDescr];
- //pred
- //NSPredicate *pred = [NSPredicate predicateWithString:@"id=1"];
- NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"typeid" ascending:YES];
- NSArray *arraySortDescriptor = [[NSArray alloc] initWithObjects:nameDescriptor, nil];
- [request setSortDescriptors:arraySortDescriptor];
- [arraySortDescriptor release];
- NSError *error;
- // NSManagedObject *aDish = nil;
- // NSNumber *id = [NSNumber numberWithInt:1];
- NSArray *objects = [context executeFetchRequest:request error:&error];
- if(objects != nil){
- self.list = objects;
- }
HotelAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
//connection
NSManagedObjectContext *context = [appDelegate managedObjectContext];
//table
NSEntityDescription *entityDescr =[NSEntityDescription entityForName:@"Dishes" inManagedObjectContext:context];
//query
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescr];
//pred
//NSPredicate *pred = [NSPredicate predicateWithString:@"id=1"]; NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"typeid" ascending:YES];
NSArray *arraySortDescriptor = [[NSArray alloc] initWithObjects:nameDescriptor, nil];
[request setSortDescriptors:arraySortDescriptor];
[arraySortDescriptor release]; NSError *error;
// NSManagedObject *aDish = nil;
// NSNumber *id = [NSNumber numberWithInt:1];
NSArray *objects = [context executeFetchRequest:request error:&error]; if(objects != nil){
self.list = objects;
}
需要拿已存在于coredata中的文件的时候,就用上面的步骤就可以咯 拿到的数据就在最后的self.list中了
可以看到上面的tableView是自己绘制的,先看下面代码:
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSUInteger row = [indexPath row];
- NSManagedObject *theObj = [self.list objectAtIndex:row];
- NSNumber *id = [theObj valueForKey:@"id"];
- NSInteger typeid = [[theObj valueForKey:@"typeid"] intValue];
- NSLog(@"tpyeid:%d",typeid);
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- UIColor *elemBgColor = [UIColor clearColor];
- UIImageView *img = [[UIImageView alloc] init];
- img.frame = CGRectMake(kX, kY, kRowHeight -10, kRowHeight -10);
- img.tag = kImage;
- [cell.contentView addSubview:img];
- [img release];
- UILabel *nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(65, 0, 100, 25)];
- nameLbl.font = [UIFont systemFontOfSize:14];
- nameLbl.tag = kName;
- nameLbl.backgroundColor = elemBgColor;
- [cell.contentView addSubview:nameLbl];
- [nameLbl release];
- UILabel *typeLbl = [[UILabel alloc] initWithFrame:CGRectMake(160, 0, 70, 25)];
- typeLbl.font = [UIFont systemFontOfSize:14];
- typeLbl.tag = kType;
- typeLbl.backgroundColor = elemBgColor;
- [cell.contentView addSubview:typeLbl];
- [typeLbl release];
- UILabel *priceLbl = [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 50, 25)];
- priceLbl.font =[UIFont systemFontOfSize:14];
- priceLbl.tag = kPrice;
- priceLbl.backgroundColor = elemBgColor;
- [cell.contentView addSubview:priceLbl];
- [priceLbl release];
- UILabel *introLbl = [[UILabel alloc] initWithFrame:CGRectMake(60, 25, 160, 30)];
- introLbl.tag = kIntro;
- introLbl.backgroundColor = elemBgColor;
- introLbl.numberOfLines = 2;
- introLbl.textColor = [UIColor grayColor];
- introLbl.font = [UIFont systemFontOfSize:12];
- [cell.contentView addSubview:introLbl];
- [introLbl release];
- UILabel *btnBgLbl = [[UILabel alloc] initWithFrame:CGRectMake(230, 25, 60, 30)];
- btnBgLbl.backgroundColor = elemBgColor;
- [cell.contentView addSubview:btnBgLbl];
- [btnBgLbl release];
- UIButton *orderBtn = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
- orderBtn.frame = CGRectMake(230, 32, 60, 20);
- [orderBtn setTitle:@"order" forState:UIControlStateNormal];
- [orderBtn addTarget:self action:@selector(order:) forControlEvents:UIControlEventTouchUpInside];
- [cell.contentView addSubview:orderBtn];
- }
- cell.tag = 1 + [indexPath row];
- TableCellView *cellView = [[TableCellView alloc] init];
- cellView._count = [self.list count];
- cellView._index = [indexPath row];
- cell.backgroundView = cellView;
- [cellView release];
- NSString *imageName = [NSString stringWithFormat:@"%d.jpg",[id intValue]];
- UIImageView *img = (UIImageView *)[cell.contentView viewWithTag:kImage];
- img.image = [UIImage imageNamed:imageName];
- UILabel *nameLbl = (UILabel *)[cell.contentView viewWithTag:kName];
- nameLbl.text = [theObj valueForKey:@"name"];//[list objectAtIndex:[indexPath row]];
- UILabel *typeLbl = (UILabel *)[cell.contentView viewWithTag:kType];
- typeLbl.text = [theObj valueForKey:@"type"];
- UILabel *priceLbl = (UILabel *)[cell.contentView viewWithTag:kPrice];
- NSNumber *nPrice = [theObj valueForKey:@"price"];
- priceLbl.text = [NSString stringWithFormat:@"¥%d",[nPrice intValue]];
- UILabel *introLbl = (UILabel *)[cell.contentView viewWithTag:kIntro];
- NSString *introText = [theObj valueForKey:@"intro"];
- if([introText length] > 70){
- introText = [introText substringToIndex:70];
- introText = [introText stringByAppendingString:@"..."];
- }
- introLbl.text = introText;
- return cell;
- }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSManagedObject *theObj = [self.list objectAtIndex:row];
NSNumber *id = [theObj valueForKey:@"id"];
NSInteger typeid = [[theObj valueForKey:@"typeid"] intValue];
NSLog(@"tpyeid:%d",typeid);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIColor *elemBgColor = [UIColor clearColor];
UIImageView *img = [[UIImageView alloc] init];
img.frame = CGRectMake(kX, kY, kRowHeight -10, kRowHeight -10);
img.tag = kImage;
[cell.contentView addSubview:img];
[img release];
UILabel *nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(65, 0, 100, 25)];
nameLbl.font = [UIFont systemFontOfSize:14];
nameLbl.tag = kName;
nameLbl.backgroundColor = elemBgColor;
[cell.contentView addSubview:nameLbl];
[nameLbl release];
UILabel *typeLbl = [[UILabel alloc] initWithFrame:CGRectMake(160, 0, 70, 25)];
typeLbl.font = [UIFont systemFontOfSize:14];
typeLbl.tag = kType;
typeLbl.backgroundColor = elemBgColor;
[cell.contentView addSubview:typeLbl];
[typeLbl release];
UILabel *priceLbl = [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 50, 25)];
priceLbl.font =[UIFont systemFontOfSize:14];
priceLbl.tag = kPrice;
priceLbl.backgroundColor = elemBgColor;
[cell.contentView addSubview:priceLbl];
[priceLbl release];
UILabel *introLbl = [[UILabel alloc] initWithFrame:CGRectMake(60, 25, 160, 30)];
introLbl.tag = kIntro;
introLbl.backgroundColor = elemBgColor;
introLbl.numberOfLines = 2;
introLbl.textColor = [UIColor grayColor];
introLbl.font = [UIFont systemFontOfSize:12];
[cell.contentView addSubview:introLbl];
[introLbl release];
UILabel *btnBgLbl = [[UILabel alloc] initWithFrame:CGRectMake(230, 25, 60, 30)];
btnBgLbl.backgroundColor = elemBgColor;
[cell.contentView addSubview:btnBgLbl];
[btnBgLbl release];
UIButton *orderBtn = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
orderBtn.frame = CGRectMake(230, 32, 60, 20);
[orderBtn setTitle:@"order" forState:UIControlStateNormal];
[orderBtn addTarget:self action:@selector(order:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:orderBtn];
}
cell.tag = 1 + [indexPath row];
TableCellView *cellView = [[TableCellView alloc] init];
cellView._count = [self.list count];
cellView._index = [indexPath row];
cell.backgroundView = cellView;
[cellView release];
NSString *imageName = [NSString stringWithFormat:@"%d.jpg",[id intValue]];
UIImageView *img = (UIImageView *)[cell.contentView viewWithTag:kImage];
img.image = [UIImage imageNamed:imageName];
UILabel *nameLbl = (UILabel *)[cell.contentView viewWithTag:kName];
nameLbl.text = [theObj valueForKey:@"name"];//[list objectAtIndex:[indexPath row]];
UILabel *typeLbl = (UILabel *)[cell.contentView viewWithTag:kType];
typeLbl.text = [theObj valueForKey:@"type"];
UILabel *priceLbl = (UILabel *)[cell.contentView viewWithTag:kPrice];
NSNumber *nPrice = [theObj valueForKey:@"price"];
priceLbl.text = [NSString stringWithFormat:@"¥%d",[nPrice intValue]];
UILabel *introLbl = (UILabel *)[cell.contentView viewWithTag:kIntro];
NSString *introText = [theObj valueForKey:@"intro"];
if([introText length] > 70){
introText = [introText substringToIndex:70];
introText = [introText stringByAppendingString:@"..."];
}
introLbl.text = introText;
return cell;
}
上面的代码中,由于坐着并没有为它的tableViewCell加一个id,所以当第一次创建cell的时候,是空的,需要自己定制,定制的过程就是把各个控件位置要放好,这个我没试过,所以对上面的坐标没什么感觉,这个需要多多尝试才知道。
这里要说的有几个点:(1)、tableViewCell有一个属性是contentView是用来容纳所有在他上面出现的控件的,自己绘制cell的时候,一定要把控件加上这个view上面,然后还有一个backgroundView是所有子view的最后面那个,在contentView上面。
(2)、本例中,cell的背景是自绘的,我不会,所以TableCellView类的代码看不太懂,有兴趣的朋友自己去研究下。
(3)、UIView有个属性tag,还有一个方法是viewWithTag.
tag是一个自己定义的常数,用来标记一个对象。viewWithTag方法呢,就是返回匹配给定的tag的view。
- -(IBAction) add:(id)sender {
- AddController *addC = [[AddController alloc] initWithNibName:@"AddController" bundle:nil];
- [self.navigationController pushViewController:addC animated:YES];
- //self.navigationController.navigationBarHidden = NO;
- [addC release];
- }
-(IBAction) add:(id)sender {
AddController *addC = [[AddController alloc] initWithNibName:@"AddController" bundle:nil];
[self.navigationController pushViewController:addC animated:YES];
//self.navigationController.navigationBarHidden = NO;
[addC release];
}
上面的代码是界面中右上角i按钮的响应方法,可以看到上面这种实现navigation跳转的方法是用push 对应的在返回的时候就用pop。这是在segue出现前的一个实现跳转的方法,现在的话 有了segue,就不用这样做咯。

这个就是按完i按钮后来到的添加新菜系的界面xib文件。
由于我主要是讲我的收获,所以在这个界面我只想讲怎么往coredata中添加新元组咯
- -(IBAction) add:(id)sender {
- if([name.text length]*[price.text length]*[type.text length]*[image.text length]*[intro.text length] == 0){
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"All fields needed!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }else{
- HotelAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
- //connection
- NSManagedObjectContext *context = [appDelegate managedObjectContext];
- //table
- NSEntityDescription *entityDescr =[NSEntityDescription entityForName:@"Dishes" inManagedObjectContext:context];
- //query
- NSFetchRequest *request = [[NSFetchRequest alloc] init];
- [request setEntity:entityDescr];
- //pred
- //NSPredicate *pred = [NSPredicate predicateWithString:@"id=1"];
- NSError *error;
- NSManagedObject *aDish = nil;
- NSNumber *id = [NSNumber numberWithInt:1];
- NSArray *objects = [context executeFetchRequest:request error:&error];
- if(objects != nil){
- aDish = [objects lastObject];
- id = [aDish valueForKey:@"id"];
- id = [NSNumber numberWithInt:[id intValue]+1];
- }
- aDish = [NSEntityDescription insertNewObjectForEntityForName:@"Dishes" inManagedObjectContext:context];
- [aDish setValue:id forKey:@"id"];
- [aDish setValue:name.text forKey:@"name"];
- [aDish setValue:[NSNumber numberWithInt:[price.text intValue]] forKey:@"price"];
- [aDish setValue:type.text forKey:@"type"];
- [aDish setValue:image.text forKey:@"image"];
- [aDish setValue:intro.text forKey:@"intro"];
- [request release];
- [context save:&error];
- [self clearFields];
- }
- }
-(IBAction) add:(id)sender {
if([name.text length]*[price.text length]*[type.text length]*[image.text length]*[intro.text length] == 0){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"All fields needed!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}else{
HotelAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
//connection
NSManagedObjectContext *context = [appDelegate managedObjectContext];
//table
NSEntityDescription *entityDescr =[NSEntityDescription entityForName:@"Dishes" inManagedObjectContext:context];
//query
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescr];
//pred
//NSPredicate *pred = [NSPredicate predicateWithString:@"id=1"];
NSError *error;
NSManagedObject *aDish = nil;
NSNumber *id = [NSNumber numberWithInt:1];
NSArray *objects = [context executeFetchRequest:request error:&error];
if(objects != nil){
aDish = [objects lastObject];
id = [aDish valueForKey:@"id"];
id = [NSNumber numberWithInt:[id intValue]+1];
}
aDish = [NSEntityDescription insertNewObjectForEntityForName:@"Dishes" inManagedObjectContext:context];
[aDish setValue:id forKey:@"id"];
[aDish setValue:name.text forKey:@"name"];
[aDish setValue:[NSNumber numberWithInt:[price.text intValue]] forKey:@"price"];
[aDish setValue:type.text forKey:@"type"];
[aDish setValue:image.text forKey:@"image"];
[aDish setValue:intro.text forKey:@"intro"];
[request release];
[context save:&error];
[self clearFields];
}
}
上面的代码是add按钮的响应方法,看完就知道了咯。
、
这个界面要讲的就是view的动画。这个程序中,左右滑动,可以实现翻页,看上一道菜或下一道菜,这个对我来说很有用。
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- //int count = [touches count];
- //NSLog(@"count=%d",count);
- UITouch *touch = [touches anyObject];
- CGPoint location = [touch locationInView:self.view];
- self.lastLoction = location;
- moveChanged = NO;
- }
- - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
- }
- - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- CGPoint location = [[touches anyObject] locationInView:self.view];
- lastLoction = location;
- }
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- CGPoint location = [touch locationInView:self.view];
- if(!moveChanged && fabs(location.x - lastLoction.x) > 60 && fabs(location.y - lastLoction.y) < 25){
- moveChanged = YES;
- [UIView beginAnimations:nil context:imageView];
- [UIView setAnimationDuration:1.0];
- [UIView setAnimationTransition:( location.x - lastLoction.x > 0? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown) forView:self.view cache:YES];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDidStopSelector:@selector(onAnimationStop:finished:context:)];
- [UIView commitAnimations];
- NSUInteger count = [self.managedObjects count];
- if(location.x - lastLoction.x >0){//right
- if(currentRowIndex < count-1){
- currentRowIndex = currentRowIndex +1;
- }
- }else{//left
- if(currentRowIndex > 0){
- currentRowIndex = currentRowIndex -1;
- }
- }
- self.theObj = [self.managedObjects objectAtIndex:currentRowIndex];
- NSNumber *id = [self.theObj valueForKey:@"id"];
- NSLog(@"%d",[id intValue]);
- NSLog(@"distance:%f",location.x - lastLoction.x);
- self.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",[id intValue]]];
- NSMutableString *title = [[NSMutableString alloc] init];
- [title appendString: [theObj valueForKey:@"name"]];
- [title appendString:@" "];
- [title appendString:[theObj valueForKey:@"type"]];
- NSNumber *price = [theObj valueForKey:@"price"];
- [title appendString:[NSString stringWithFormat:@"¥%d",[price intValue]]];
- self.nameLbl.text = title;
- self.introText.text = [theObj valueForKey:@"intro"];
- [title release];
- NSDictionary *theRow = [FileController readRow:currentRowIndex];
- NSUInteger orderCount = 0;
- if(theRow != nil){
- orderCount = [[theRow valueForKey:@"count"] intValue];
- }
- self.countLbl.text = [NSString stringWithFormat:@"%d",orderCount];
- lastLoction = location;
- }
- }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//int count = [touches count];
//NSLog(@"count=%d",count);
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
self.lastLoction = location;
moveChanged = NO;
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView:self.view];
lastLoction = location;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
if(!moveChanged && fabs(location.x - lastLoction.x) > 60 && fabs(location.y - lastLoction.y) < 25){
moveChanged = YES;
[UIView beginAnimations:nil context:imageView];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:( location.x - lastLoction.x > 0? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown) forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(onAnimationStop:finished:context:)];
[UIView commitAnimations];
NSUInteger count = [self.managedObjects count];
if(location.x - lastLoction.x >0){//right
if(currentRowIndex < count-1){
currentRowIndex = currentRowIndex +1;
}
}else{//left
if(currentRowIndex > 0){
currentRowIndex = currentRowIndex -1;
}
}
self.theObj = [self.managedObjects objectAtIndex:currentRowIndex];
NSNumber *id = [self.theObj valueForKey:@"id"];
NSLog(@"%d",[id intValue]);
NSLog(@"distance:%f",location.x - lastLoction.x);
self.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",[id intValue]]];
NSMutableString *title = [[NSMutableString alloc] init];
[title appendString: [theObj valueForKey:@"name"]];
[title appendString:@" "];
[title appendString:[theObj valueForKey:@"type"]];
NSNumber *price = [theObj valueForKey:@"price"];
[title appendString:[NSString stringWithFormat:@"¥%d",[price intValue]]];
self.nameLbl.text = title;
self.introText.text = [theObj valueForKey:@"intro"];
[title release];
NSDictionary *theRow = [FileController readRow:currentRowIndex];
NSUInteger orderCount = 0;
if(theRow != nil){
orderCount = [[theRow valueForKey:@"count"] intValue];
}
self.countLbl.text = [NSString stringWithFormat:@"%d",orderCount];
lastLoction = location;
}
}
- [UIView beginAnimations:nil context:imageView];
- [UIView setAnimationDuration:1.0];
- [UIView setAnimationTransition:( location.x - lastLoction.x > 0? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown) forView:self.view cache:YES];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDidStopSelector:@selector(onAnimationStop:finished:context:)];
- [UIView commitAnimations];
[UIView beginAnimations:nil context:imageView];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:( location.x - lastLoction.x > 0? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown) forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(onAnimationStop:finished:context:)];
[UIView commitAnimations];
截取的这几句代码就是一个动画的过程.
第二个标签是读取已经下单的菜,这个没什么好说的 和第一个标签的第一个页面很相似。
第三个界面是一个可以发表建议的界面,用到了segment controller来分两个界面,一个是写的 一个是看全部的历史建议的。
切换segmentController上面的标签时,会响应valueChange方法,可以在里面判断是要显示哪个界面。
POST请求的发送也可以再复习一下:
- NSString *postMsg =[NSString stringWithFormat:@"user=%@&content=%@",self.name.text,self.textView.text];
- NSData *postData = [postMsg dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
- NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://bula.kilu.net/post.php"]];
- [request setHTTPMethod:@"POST"];
- [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
- [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
- [request setHTTPBody:postData];
- [NSURLConnection connectionWithRequest:request delegate:self];
NSString *postMsg =[NSString stringWithFormat:@"user=%@&content=%@",self.name.text,self.textView.text];
NSData *postData = [postMsg dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://bula.kilu.net/post.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData]; [NSURLConnection connectionWithRequest:request delegate:self];
好了 我学到的东西是这些,还有一些是我看不懂的 对于自己绘制一些view的方法我还是不会,需要补补。
源码我待会会上传,有兴趣的朋友下载去研究下咯 不错的学习资料。,如果运行的时候说差哪一张图片的什么 就随便放张进去文件夹里面然后按它说的给个名字就行了,不影响代码研究。
上传好了 源码地址:ios点餐系统
ios 点餐系统的更多相关文章
- 非常不错的点餐系统应用ios源码完整版
该源码是一款非常不错的点餐系统应用,应用源码齐全,运行起来非常不错,基本实现了点餐的一些常用的功能,而且界面设计地也很不错,是一个不错的ios应用学习的例子,喜欢的朋友可以下载学习看看,更多ios源码 ...
- 很不错的点餐系统应用ios源代码完整版
该源代码是一款很不错的点餐系统应用,应用源代码齐全,执行起来很不错,基本实现了点餐的一些经常使用的功能,并且界面设计地也很不错,是一个不错的ios应用学习的样例,喜欢的朋友能够下载学习看看,很多其它i ...
- 点餐系统web版功能需求
餐厅到店点餐系统需求分析 (版本v1.0.0) 成文信息 主题词: 需求分析 作 者: 14商软ETC 文档类别: 审 核: 批 准: 文档性 ...
- [课程设计]Scrum 3.8 多鱼点餐系统开发进度(留言反馈系统设计)
Scrum 3.8 多鱼点餐系统开发进度(留言反馈系统设计) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点餐系统 ...
- [课程设计]Scrum 3.7 多鱼点餐系统开发进度(留言板选择方案)
Scrum 3.7 多鱼点餐系统开发进度(留言板选择方案) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点餐系统W ...
- [课程设计]Scrum 3.6 多鱼点餐系统开发进度(用户测试反馈页面构思&留言板设计)
Scrum 3.6 多鱼点餐系统开发进度(用户测试反馈页面构思&留言板设计) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团 ...
- [课程设计]Scrum 3.5 多鱼点餐系统开发进度(修复Bug&美化页面)
Scrum 3.5 多鱼点餐系统开发进度(修复Bug&美化页面) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅 ...
- [课程设计]Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面)
Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队 ...
- [课程设计]Scrum 3.3 多鱼点餐系统开发进度(下单详细信息页面设计)
Scrum 3.3 多鱼点餐系统开发进度(下单详细信息页面设计) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点 ...
随机推荐
- 2013 Noip提高组 Day1
3285 转圈游戏 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description ...
- 调用Web API将文件上传到服务器的方法(.Net Core)
最近遇到一个将Excel通过Web API存到服务器的问题,其中涉及到Excel的读取.调用API.Web API怎么进行接收. 一. Excel的读取.调用API Excel读取以及调用API的代 ...
- python-selenium-robotframework安装问题
背景 当前系统安装了两个不同版本的python,分别是python27和python36(如图1),如图 说明 系统安装的两个python版本,python2中的python.exe默认不做修改:py ...
- Pycharm2019.1.2永久激活
五月八日Pycharm更新至2019.1.2,小伙们是否也及时更新了呢?值得注意的是以前的激活方式已不适用于本次更新,这里分享最新的激活方法,有需要的同学请扫码关注我的公众号获取 重申:如果经济条件允 ...
- C 语言实例 - 二进制与十进制相互转换
C 语言实例 - 二进制与十进制相互转换 C 语言实例 C 语言实例 二进制转与十进制相互转换. 实例 - 二进制转换为十进制 #include <stdio.h> #include &l ...
- Unrecogized font family ‘Ionicons’ 在ios上报错,android正常
解决方法: react-native link react-native-vector-icons 很多模块都需要link一下
- POJ3744(概率dp)
思路:一长段概率乘过去最后会趋于平稳,所以因为地雷只有10个,可以疯狂压缩其位置,这样就不需要矩阵乘优化了.另外初始化f[0] = 0, f[1] = 1,相当于从1开始走吧.双倍经验:洛谷1052. ...
- 105 Construct Binary Tree from Preorder and Inorder Traversal 从前序与中序遍历序列构造二叉树
给定一棵树的前序遍历与中序遍历,依据此构造二叉树.注意:你可以假设树中没有重复的元素.例如,给出前序遍历 = [3,9,20,15,7]中序遍历 = [9,3,15,20,7]返回如下的二叉树: ...
- python_19(Django外键)
第1章 Django ORM相关操作 1.1 在一个py文件中使用django项目 1.2 返回QuerySet对象的方法有 1.2.1 特殊的QuerySet 1.3 返回具体对象的 1.4 返回布 ...
- 利用apache限制IP并发数和下载流量控制
一,为什么要对IP并发数,下载流量进行控制 说正题之前,先给大家讲个故事,那是在2007年,我进了一家公司,当时我们正在给达芙妮做电子商务网,www.idaphne.com.从三月份开始做的吧,九月份 ...