ios开发备忘

本文汇总了iOS开发中常见的技巧,包括直接打开AppStore评论页面、修改UIPageControl图标、解决iPad上UIView使用FormSheetSize模式时键盘问题等。此外还介绍了如何处理UIActionSheet按钮点击不灵敏、保持UITextView焦点不丢失、显示和隐藏网络请求状态等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

IOS 常用开发 参考: http://www.cnblogs.com/martin1009/category/332135.html


1:直接打开app store 评论页面的URL,直接更换 后面的id号就可以

// 通过 html 打开

http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=557853602

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=557853602"]];

// 直接通过 itunes 打开

NSString*strUrl =@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=557853602";

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:strUrl]];


2: 更改 UIPageControl 图标

  1. -(void)pageControlStatusImage:(int)_page{
  2. NSArray*subview=self.firstPageControl.subviews;//获取所有子视图
  3. for(NSIntegeri=0;i<[subviewcount];i++){
  4. UIImageView*_dotView=[subviewobjectAtIndex:i];
  5. if(i==_page){
  6. //imagew=6h=6
  7. _dotView.image=_pageNormalImage;
  8. }else{
  9. _dotView.image=_pageHighlightedImage;
  10. }
  11. }
  12. }

3:UIAlertView Frame

  1. defaultframex=0.000000,y=0.000000,w=284.000000,h=141.000000
  2. title:x=12.000000,y=15.000000,w=260.000000,h=23.000000
  3. message:x=12.000000,y=45.000000,w=260.000000,h=21.000000
  4. leftbut:x=11.000000,y=82.000000,w=127.000000,h=43.000000
  5. rightbut:x=146.000000,y=82.000000,w=127.000000,h=43.000000

4: ipad 上UIView 使用 Form Sheet Size 模式时,

UITextField,[textFieldresignFirstResponder] 不能关闭软键盘问题

解决方法:

在 .h .m 文件中 重写disablesAutomaticKeyboardDismissal 方法

  1. -(BOOL)disablesAutomaticKeyboardDismissal;
  2. -(BOOL)disablesAutomaticKeyboardDismissal
  3. {
  4. returnNO;
  5. }

如果在 UINavigationController 中使用,可以用如下方法重写,之后在 需要用到的地方import

添加File:UINavigationController+KeyboardDismiss.h UINavigationController+KeyboardDismiss.m

  1. #import<Foundation/Foundation.h>
  2. //解决FromSheetUIViewtextfiled不能隐藏键盘的问题
  3. @interfaceUINavigationController(KeyboardDismiss)
  4. -(BOOL)disablesAutomaticKeyboardDismissal;
  5. @end
  6. #import"UINavigationController+KeyboardDismiss.h"
  7. @implementationUINavigationController(KeyboardDismiss)
  8. -(BOOL)disablesAutomaticKeyboardDismissal
  9. {
  10. returnNO;
  11. }
  12. @end


5: UIActionSheet 最后一个 按钮 点击时不太好用,一般要点击道 button 上半部才行

UIActionSheet*actionSheet = [[UIActionSheetalloc]

initWithTitle:@“aaa”

delegate:nil

cancelButtonTitle:nil

destructiveButtonTitle:nil

otherButtonTitles:@"aaa",@"Cancel",nil];

//[actionSheet showInView:self.view]; ---- 把这行换掉,用下行的方法来显示

[actionSheetshowInView:[UIApplicationsharedApplication].keyWindow];


6: UITableViw 的 cell 中 有 UITextFiled 控件,点击出来软件盘后,如果 UITableView 此时刷新 relaoddata,则软件盘会因为 失去 焦点而 自动隐藏

如果想要 软件盘还在,则需要 改变UITextFiled 的焦点 到UITableViw 之外的 另一个UITextFiled 上即可

7: ios 设备 左上角 网络请求状态 显示/隐藏

//显示网络活动标志:
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

//隐藏网络活动标志:
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];


// ---------------

1、调用 自带mail

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzlzh.com"]];

2、调用 电话phone

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];
iOS应用内拨打电话结束后返回应用
一般在应用中拨打电话的方式是:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];

使用这种方式拨打电话时,当用户结束通话后,iphone界面会停留在电话界面。
用如下方式,可以使得用户结束通话后自动返回到应用:
UIWebView*callWebview =[[UIWebView alloc] init];
NSURL *telURL =[NSURL URLWithString:@"tel:10086"];// 貌似tel:// 或者 tel: 都行
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
//记得添加到view上
[self.view addSubview:callWebview];

 还有一种私有方法:(可能不能通过审核)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10086"]];

3、调用自带 浏览器 safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];

4、调用 SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];

调用phone可以传递号码,调用SMS 只能设定号码,不能初始化SMS内容。

若需要传递内容可以做如下操作:
加入:MessageUI.framework

#import <MessageUI/MFMessageComposeViewController.h>

实现代理:MFMessageComposeViewControllerDelegate

调用sendSMS函数
//内容,收件人列表
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];

if([MFMessageComposeViewController canSendText])

{

controller.body = bodyOfMessage;

controller.recipients = recipients;

controller.messageComposeDelegate = self;

[self presentModalViewController:controller animated:YES];

}

}

// 处理发送完的响应结果
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];

if (result == MessageComposeResultCancelled)
NSLog(@"Message cancelled")
else if (result == MessageComposeResultSent)
NSLog(@"Message sent")
else
NSLog(@"Message failed")
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值