19 2011-7
UIImage *image = [[UIImage alloc] initWithData:data];//大图
CGRect imageRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
CGSize itemSize = CGSizeMake(w,h);
UIGraphicsBeginImageContext(itemSize);
[image drawInRect:imageRect];
...
19 2011-7
- (void)viewDidLoad
{
NSString *homeDirectoryPath = NSHomeDirectory();
NSString *imagePath = [homeDirectoryPath stringByAppendingString:@"/graph.png"];
NSLog(@"Image: %@", imagePath);
if (![[NSFileManager
defaultManager] fileExistsAtPath:imagePath isDirectory:NULL])
...
19 2011-7
在Xcode中安装部署JSON
1.下载JSON_2.3.dmg到电脑,双击安装.下载地址:http://code.google.com/p/json-framework/downloads/list?can=1&;q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount
如下图:
2.把上图中JSON目录拖拽到Xcode中classes目录,然后在自己的单元文件中就可以使用JSON了(例如:#import "JSON/JSON.h")。
...
19 2011-7
原来简单解释过属性定义(Property) ,并且提起了简单的retain,copy,assign的区别。那究竟是有什么区别呢?
assign就不用说了,因为基本上是为简单数据类型准备的,而不是NS对象们。
Retain vs. Copy!!
copy: 建立一个索引计数为1的对象,然后释放旧对象
retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1
那上面的是什么该死的意思呢?
Copy其实是建立了一个相同的对象,而retain不是:
比如一个NSString对象,地址为0×1111,内容为@”STR”
...
19 2011-7
在网络应用程序中,经常需要多任务连接来提高程序的性能。比如多任务下载,多任务HTTP请求等,即线程控制模型中的工作群模型。使用 NSOperation 可以很容易实现这个功能。下面就以使用NSOperation处理并行的HTTP请求为例子,说明其用法。
首先准备一个 NSOperation 的子类,用于处理 HTTP 请求。
@interface RequestOperation : NSOperation {
NSURLRequest* _request;
NSMutableData* _data;
...
19 2011-7
======================================
objective-c代码:
======================================
NSLog(@"POST");
NSArray *arr = [[NSArray
alloc] initWithObjects:@"username",@"password",nil];
NSString *requestString = [NSString stringWithFormat:@"json=%@", [arr JSONRepresentation], nil];;
...
19 2011-7
1。创建view-based工程图
2.用ib打开...controller.xib文件,拖入一个table view。
3。在classes目录下创建UITableView文件,取名为BagItemCell。
.h文件,.m文件不用改
#import
@interface BagItemCell : UITableViewCell {
IBOutlet
UILabel *lblName;
}
@property (nonatomic,retain) UILabel *lblName;
...
19 2011-7
AsyncImageView.h文件
@interface AsyncImageView : UIView {
NSURLConnection* connection;
NSMutableData* data;
}
@end
AsyncImageView.m文件
@implementation AsyncImageView
- (void)loadImageFromURL:(NSURL*)url {
if (connection!=nil) { [connection release; }
...
19 2011-7
在View的UITextField中经常需要输入完文字后隐藏软键盘,要实现着一点要让View的Controller实现UITextFieldDelegate代理,然后编写相应的代码。
#import
@interface TestVeiwController : UIViewController {
IBOutlet UITextField *txt;
}
@property (nonatomic,retain) UITextField *txt;
...
19 2011-7
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==currentIndex){
return UITableViewCellAccessoryCheckmark;
}
else{
return UITableViewCellAccessoryNone;
...