iOS 学习中问题及解决方案

iOS 开发错误 及 解决方法 ------------------------------------

Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super. 解决方法:去掉选择报错得xlb文件。 在xcode 中去掉 auto layout

---------------------------

loaded the "YddHotelBlogViewController" nib but the view outlet was not set. (null) 解决方法:由于 xlb控件 没有和ViewCtroller关联。导致的。 关联上就ok

--------------

UITableView 添加tableFooterView: 解决方法:self.hotelBlogTableView.tableFooterView = self.footerView;

UIButton 创建方法 解决方法:UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

--------------------------------

关于iOS http请求 解决方法: NSString *post = [NSString stringWithFormat:@"loginname=%@&loginpassword=%@&loginType=%@&appType=%@&deviceUuid=%@",userName,md5Password,@"IOS",@"APP-18",@"fe50812e1e5ea5b98ed90e3e620f8fbc16bb363f"]; NSLog(@"post:%@",post); NSString *urlStr=@"http://api.yododo.com/mobile/v2/saleLogin.ydd"; NSLog(@"urlStr=%@",urlStr); //将NSSrring格式的参数转换格式为NSData,POST提交必须用NSData数据。 NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]]; NSLog(@"postLength=%@",postLength); NSURL *url = [NSURL URLWithString:urlStr]; NSMutableURLRequest *request= [NSMutableURLRequest requestWithURL:url]; //设置请求头 [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; //post提交 [request setHTTPMethod:@"POST”]; //get提交 方式 [request setHTTPMethod:@"GET”]; //数据长度 [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; //传输数据 [request setHTTPBody:postData]; //定义 NSHTTPURLResponse* urlResponse = nil; NSError *error = [[NSError alloc] init]; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; //将NSData类型的返回值转换成NSString类型 NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"user login check result:%@",result); [self alertView:@"登录结果" message:result];

---------------------------------

UITableViewCell 使用: 解决方法:创建xlb继承UITableViewCell。 在cellForRowAtIndexPath中创建使用

-------------------------

 视频播放: 解决方法: 导入视频框架:#import <MediaPlayer/MediaPlayer.h> //NSString *fileName=[NSString stringWithFormat:@""]; //视频文件路径 //NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"]; //视频URL NSURL *url = [NSURL fileURLWithPath:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]; //视频播放对象 MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:url]; //设置播放源 类型 movie.movieSourceType = MPMovieSourceTypeFile; //自动播放 movie.shouldAutoplay = YES; //控制器 样式 movie.controlStyle = MPMovieControlStyleNone; //有图像 有声音。 [movie.view setFrame:CGRectMake(30, 210, 250, 350)]; //添加 当前页中 [self.view addSubview:movie.view]; //预播放 [movie prepareToPlay]; //播放结束时 增加通知 NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter addObserver:self selector:@selector(moviePlayerPreloadFinish:) name:MPMoviePlayerContentPreloadDidFinishNotification object:movie ]; [movie play];

---------------------

Undefined symbols for architecture i386:和"_OBJC_CLASS_$_xx", referenced from:

解决方法: http://blog.csdn.net/azhou_hui/article/details/18312047

  -----------------------------------

ios 数据库操作:项目使用的时sqlite

http://blog.csdn.net/zhuzhihai1988/article/details/7878093  sqllite语法

  在项目运行时发现一直都找不到数据库表。 后面了解到是ios的虚拟机缓存了sqlite文件。找到ios的虚拟机目录删除打包文件。 之后重新运行。问题解决。 

//sqlite3_stmt 类似于 jdbc操作的statement对象

sqlite3_stmt *get_statement = nil;

 //查询 根据时间搜索历史城市表记录取前5条   

NSString *sqlString = [NSString stringWithFormat:@"select *  from SearchHistoryPlace order by dateTime desc limit 0,5"];

    const char *sql = [sqlString UTF8String];

    

    NSLog(@"result:%d",sqlite3_prepare_v2(database, sql, -1, &get_statement, NULL));

    //执行准备sql

    if (sqlite3_prepare_v2(database, sql, -1, &get_statement, NULL) != SQLITE_OK){

sqlite3_reset(get_statement);

return nil;

}

    

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

     //从statement

while (sqlite3_step(get_statement) == SQLITE_ROW){

        YddSearchHistoryPlace *disCity = [[YddSearchHistoryPlace alloc]init];

        //sqlite3_column_text 查询text类型的列值

        disCity.placeId = [NSString stringWithCString:(char *)sqlite3_column_text(get_statement, 0) encoding:NSUTF8StringEncoding];

        disCity.cityName = [NSString stringWithCString:(char *)sqlite3_column_text(get_statement, 1) encoding:NSUTF8StringEncoding];

        

        [cities addObject:disCity];

}

sqlite3_reset(get_statement);

return cities;

 

//插入

 sqlite3_stmt *insert_statement = nil;

    const char *sql = [[NSString stringWithFormat:@"INSERT INTO SearchHistoryPlace VALUES ('%@','%@','%@')",yddDistributionCity.placeId,yddDistributionCity.cityName,yddDistributionCity.dateTime]UTF8String];

    if(sqlite3_prepare_v2(database, sql, -1, &insert_statement, nil) != SQLITE_OK){

    }

    sqlite3_step(insert_statement);

    sqlite3_reset(insert_statement);

 

//更新

 sqlite3_stmt *insert_statement = nil;

    const char *sql = [[NSString stringWithFormat:@"INSERT INTO SearchHistoryPlace VALUES ('%@','%@','%@')",yddDistributionCity.placeId,yddDistributionCity.cityName,yddDistributionCity.dateTime]UTF8String];

    if(sqlite3_prepare_v2(database, sql, -1, &insert_statement, nil) != SQLITE_OK){

    }

    sqlite3_step(insert_statement);

    sqlite3_reset(insert_statement);

 //查看数据库是否存在该表

 select count(*) from sqlite_master where type='table' and name = '%@'

//创建表

CREATE TABLE IF NOT EXISTS SearchHistoryPlace

--------------------------------

//自定义背景色
self.duoduoquanBtn.backgroundColor = [NSStringUtil colorWithHexString:@"#FEFEE8"];

//字符串转化为 转换为UIColor

(UIColor *) colorWithHexString: (NSString *)color

{

    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]] uppercaseString];

    

    // String should be 6 or 8 characters

    if ([cString length] < 6) {

        return [UIColor clearColor];

    }

    

    // strip 0X if it appears

    if ([cString hasPrefix:@"0X"])

        cString = [cString substringFromIndex:2];

    if ([cString hasPrefix:@"#"])

        cString = [cString substringFromIndex:1];

    if ([cString length] != 6)

        return [UIColor clearColor];

    

    // Separate into r, g, b substrings

    NSRange range;

    range.location = 0;

    range.length = 2;

    

    //r

    NSString *rString = [cString substringWithRange:range];

    

    //g

    range.location = 2;

    NSString *gString = [cString substringWithRange:range];

    

    //b

    range.location = 4;

    NSString *bString = [cString substringWithRange:range];

    

    // Scan values

    unsigned int r, g, b;

    [[NSScannerscannerWithString:rString] scanHexInt:&r];

    [[NSScannerscannerWithString:gString] scanHexInt:&g];

    [[NSScannerscannerWithString:bString] scanHexInt:&b];

    

    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];

}

 ------------------

 

猜你喜欢

转载自zeng7960983.iteye.com/blog/2108469