ssh root@192.168.0.13
jxxxxxe
Photo dir: /private/var/mobile/Media/DCIM
Video: /private/var/mobile/Media/Photos
address book:
/private/var/root/Library/AddressBook
/private/var/mobile/Library/AddressBook
SMS: /private/var/mobile/Library/SMS
ios library
http://developer.apple.com/library/ios/navigation/
submit to app store
http://www.hf80.cn/appstore149/
http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/000-Introduction/introduction.html#//apple_ref/doc/uid/TP40007959
http://www.cocoachina.com/bbs/simple/?t14781.html
如何联机调试和发布程序(99$)
http://www.cocoachina.com/bbs/read.php?tid-7923.html
HelloWorld
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhone101/Articles/01_CreatingProject.html%23//apple_ref/doc/uid/TP40007514-CH3-SW3
Your first ios applcation
https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/JumpRightIn/iPhone101/Articles/00_Introduction.html%23//apple_ref/doc/uid/TP40011343-TP40007514
Create an iphone application
http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Creating_an_iPhone_App/_index.html%23//apple_ref/doc/uid/TP40007595
博客
http://liucheng.easymorse.com/?paged=4
http://fei263.blog.163.com/blog/static/927937242009526112420548/
游戏开发
http://www.starming.com/index.php?action=plugin&v=wave&tpl=union&ac=grouptags&gid=1000003370
Create UI
1. Create am empty project. create main.xib, in plist file ad row "Main nib file base name" with value "main" (Main nib file base name(iphone) is for iphone, "Main nib file base name(ipad)" is for ipad, you can add both rows).
2. Use file menu "File"->"New"->"new file" to create a new ui resource "main.xib"
But this time, there is noting will be displayed besides a blank window if you run it.
3. In Object Library, drag and drop a "window" into main.xib, which will be displayed as default window. If you change the background color of the window, it will take effect.
4. Then drag and drop a "view controller" into main.xib. click window object and drag the line into view controller, which will set the view controller as "rootviewcontroller" of the window. Then drag and drop view object into view controller object and the view will be display on top the window.
SET root view controller in code
5. The alternative way of step 3.4.5, is create new view controller using "file"->"new", then write code in appdelegate.m
self.window.rootViewController = self.viewController
and add line in app delegate.h
给app加logo( enable logo for your applicati
加入项目logo57x57.png 和logo72x72.png
然后在target->info 添加行
Icon file => logo57x57.png
删掉行 Icon files
@property (nonatomic, retain) IBOutlet SnookerScoreBoard_viewbasedViewController *viewController;
NOT USE root view controller (<ios5)
Add line in function didFinishLaunchingWithOptions of your app delagate:
[self.window addSubview:tabBarController.view];
NOTIC:
"file’s owner" should be UIApplication
then add delegate as outlet of file’s owner
NOTIC:
If you choose load main window from xib like step above, you need to remove the line like following from the didFinishLaunchingWithOptions
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Manually create window and viewcontroller:
Alternative to step 1,2,3, you can use code in appdelete: didFinishLaunchingWithOptions
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
- //self.viewController = [[ViewController alloc] init];
Create View dynamically
UIImageView* bgView1 = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[bgView1 setImage:[UIImage imageNamed:@"background.PNG"]];
[self.window addSubview:bgView1];
NOTICE:
Put the bgView as property should be better
The simulator is not "case sensitive" when loading image, but iphone does. Because Mac loads file ingnoring case, but iphone use accurate file name;
Full Screen
self.window.windowLevel = UIWindowLevelStatusBar + 1.0f;
ADD Property in plist file
UIStatusBarHidden= yes
为需要拉伸的控件设置背景图片( set stretchabl image as background of controller)
UIImage *buttonImageNormal = [UIImage imageNamed:@"SendButton.png"];
UIImage *stretchableButtonImageNormal = [buttonImageNormal
stretchableImageWithLeftCapWidth:12 topCapHeight:0];
//设置帽端为12px,也是就左边的12个像素不参与拉伸,有助于圆角图片美观
[btnSendSMS setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:@"SendButtonPressed.png"];
UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12topCapHeight:0];
[btnSendSMSsetBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];
Why Scrollview not scroll
Because You need to set contentsize for scrollview, you do it by code "setContentSize" or by interface build under size inspector
customized process bar
https://github.com/PascalW/PDColoredProgressview/blob/master/PDColoredProgressView.m
Get main window reference
[[UIApplication sharedApplication].delegate window]
让 UIWebView 背景透明需要以下设置
// !!! you must do this by code, not in Interface Builder
web_about.backgroundColor = [UIColor clearColor];
// !!! you must also do this in interface builder, otherwise will show a white page before loading finished !!!
web_about.opaque = NO;
关键是在HTML里:
<body style="background-color: transparent">
Conversion between string and integer
Convert NSString to int
1 |
NSString *aNumberString = @"123" ; |
2 |
int i = [aNumberString intValue]; |
Convert int to NSString
2 |
NSString *aString = [ NSString stringWithFormat: @"%d" , aNumber]; |
Remove view and all its controller
UIView* pv = [button superview];
[pv setHidden: TRUE];
NSArray * subviewsArr = [pv subviews];
for(UIView *v in subviewsArr )
{
[v removeFromSuperview];
}
// [button removeFromSuperview];
[pv removeFromSuperview];
Check network connection
Reachability *r = [Reachability reachabilityWithHostName:@"www.apple.com"];
switch ([r currentReachabilityStatus]) {
case ReachableViaWWAN:
// 你的设备使用3G网络
NSLog(@"使用3G网络");
break;
case ReachableViaWiFi:
// 你的设备使用WiFi网络
NSLog(@"使用wifi网络");
break;
case NotReachable:
// 你的设备没有网络连接
NSLog(@"没有网络");
break;
}
UIView auto resize according controller inside
[view sizeToFit]
Timer
game_timer = [NSTimer scheduledTimerWithTimeInterval:(1.0)target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
Store data and read data
// store
NSArray *Array = [NSArray arrayWithObjects:ad.session_id, nil];
NSUserDefaults *SaveDefaults = [NSUserDefaults standardUserDefaults];
[SaveDefaults setObject:Array forKey:@"sessionid"];
// read
NSUserDefaults *SaveDefaults = [NSUserDefaults standardUserDefaults];
NSArray * Array = [SaveDefaults objectForKey:@"sessionid"];
session_id = [Array objectAtIndex:0];
NSLog(@"load session id %@", session_id);
Time
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-
- [formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss:SSSS"];
-
- NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
-
- [formatter setTimeZone:timeZone];
-
- NSString *loctime = [formatter stringFromDate:date];
-
- [formatter release];
-
How to calculate size or auto resize width of UILabel to fit its content with specified font
CGSize constraintSize= CGSizeMake(label.frame.size.width,MAXFLOAT);
CGSize expectedSize = [label.text sizeWithFont:label.font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, expectedSize.width, expectedSize.height);
Use repeated picture as background (tile)
view.backgroundColor = [UIColor colorWithPatternImage:aImage]; [view setOpaque:NO];
[[view layer] setOpaque:NO];
// hide system keyboard when user click "return"
Set delegate of textfield to file owner (viewcontroller)
and add delegate method
– (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
Get current time and date
NSDate* d = [NSDate date]
Create date from string
NSDateFormatter *nsdf2=[[NSDateFormatter alloc] init];
[nsdf2 setDateStyle:NSDateFormatterShortStyle];
[nsdf2 setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate* d = [nsdf2 dateFromString:@"2012-04-01 00:00:00:"];
Trouble Shooting
[link error "Undefined symbols for architecture armv7:
"_sendHttpRequest", referenced from:
-[HomeViewController viewDidLoad] in HomeViewController.o
ld: symbol(s) not found for architecture armv7
"
with warning "implicit declaration of function ‘_sendHttpRequest’ is invalid in C99′]
This is because you call the function by c style but declare it as interface method
you should call it using sytax
[self sendHttpRequest:@"fdsaf"];
[空引用]
property 必须 @synthesize, 否则在引用时可能为空报exception
[button 不响应]
添加一个view(manually), 然后添加一个button, 但是button不响应点击事件。
解决办法, 设置添加的view的 UesrInteractionEnabled 属性
[resultView setUserInteractionEnabled: TRUE];
[import head file fail]
should use
#import "QuartzCore/CAAnimation.h"
instead of
#import "CAAnimation.h"
[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
把变量的定义从copy 改成retain就好了,因为copy返回的是一个immutable的对象
UILable cannot be displayed
You have to use[ [lb alloc] initWithFrame:CGRectMake(x,x,x,x)] to create
Cannot create without initWithFrame and setFrame afterwards.
Button cannot respond to touchupinside event
if button is inside an uiimageview, yo
1. because UIImageView userInteract is false by default, you have userInteractionEnabled:YES
2.The other possible reason is the button is outside the frame of its super view.
3. The button is coved by a transparent view
xcode hide all window when runing application
command+option+h can show all window. The reason why windows hide is unknown, maybe click or press hot-key by mistake.
button cannot be displayed in a uiview
The reason I run a animation using transform. After animation stop, I reset frame by
– (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
NSLog(@"ANIMATION stopped");
[skillsView setTransform:CGAffineTransformIdentity];
[skillsView setFrame:CGRectMake(0, 200, 200, 300)];
}
The code set frame from 0, to 200 in width, but my button is located at 200.
It’s hard to find the reason because when set the background color, the window area is enclose the button, because I set the view frame to 0, 200, 320, 300 somewhere. But the button cannot be touced. Seems you must set the frame animationDidStop
UILabel cannot display content
Because the line
[lbValue setAdjustsFontSizeToFitWidth:NO];
should set to YES, otherwise if the size of label is too small, or the font you set it too big to display in frame, then the content will be not displayed.
Exception when you rename outlet or re-associate the controller with outlet
‘NSUnknownKeyException’, reason: ‘[<MarketViewController 0x4e3b530> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key btPremierEp.’
The "btPremierEp" is the old name UI load using to load controller for view controller.
Even you check all the code and reassociate the connection between controller and code and cannot find the old name being used, but still get exception related with the old name of outlet.
Because the xib file still have the association in fileowner, goto IB, select File’s owner, and delete that association, then it works.
cannot set proper contentSize for UIScrollView
The real scrollable content size if the contentSize+frame, so if your frame is (0,0,320,480), and you content size is (320, 600), then you have set v.contentSize=CGSizeMake(0, 600-480)
Cannot send http post body to server
You cannot setHttpBody using NSString, you should use NSData.
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@%@", ad.host, ad.port, cmd]]];
[request setHTTPMethod:@"POST"];
NSData *postData = [data dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setValue:[[NSNumber numberWithInt:[postData length]]stringValue] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
if (cookie)
[request addValue:cookie forHTTPHeaderField:@"Cookie"];
else{ // first request
if (ad.session_id != nil){
NSString * c = [[NSString alloc] initWithFormat:@"_wh_session=%@;", ad.session_id];
NSLog(@"First request cookie:%@", c);
[request addValue:c forHTTPHeaderField:@"Cookie"];
}
}
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
弹出键盘挡住了输入框
– (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (self.inputTextField == textField) {
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
[UIView setAnimationDuration:animationDuration];
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
CGRect rect = CGRectMake(0.0f, VIEW_UP_SIZE,width,height);
self.view.frame = rect;
[UIView commitAnimations];
}
}
– (BOOL)textFieldShouldReturn:(UITextField *)textField {
// When the user presses return, take focus away from the text field so that the keyboard is dismissed.
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);
self.view.frame = rect;
[UIView commitAnimations];
[textField resignFirstResponder];
return YES;
}
from http://tigerszdf.blog.163.com/blog/static/45955133201010845223364/
This article is created by
开心写作网