31-40(PHC檔案,UIApplication,Info.plis,監聽return按鈕,格式化日期,openURL)

來源:互聯網
上載者:User

標籤:style   class   c   code   tar   ext   

31.監聽return按鈕

32.自動滾動表格到最後一行

33.格式化日期

34.返回每一組需要顯示的頭部標題

35.Info.plist常見的設定

36.PHC檔案

37.UIApplication

38.UIApplication的常用屬性

39.iOS7中的狀態列

40.openURL

{

一個合格的程式員是不會寫出 諸如 “摧毀地球” 這樣的程式的,
他們會寫一個函數叫 “摧毀行星”而把地球當一個參數傳進去。

}

31.點擊了return按鈕(鍵盤最右下角的按鈕)就會調用,使用此方法時, 要尊從UITextFieldDelegate協議,
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
  [self addMessage:textField.text type:MJMessageTypeMe];// 1.自己發一條訊息
  NSString *reply = [self replayWithText:textField.text];// 2.自動回複一條訊息
  [self addMessage:reply type:MJMessageTypeOther];
  self.inputView.text = nil;// 3.清空文字
  return YES;// 返回YES即可
}

 

32.自動滾動表格到最後一行
NSIndexPath *lastPath = [NSIndexPath indexPathForRow:self.messageFrames.count - 1 inSection:0];
[self.tableView scrollToRowAtIndexPath:lastPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

 

33.格式化日期
NSDate *now = [NSDate date];
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"HH:mm";
// NSDate ---> NSString
// NSString ---> NSDate
// fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
// 2014-08-09 15:45:56
// 09/08/2014 15:45:56
msg.time = [fmt stringFromDate:now];

 


34.返回每一組需要顯示的頭部標題
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
  // 1.建立頭部控制項
  HeaderView *header = [HeaderView headerViewWithTableView:tableView];
  header.delegate = self;
  // 2.給header設定資料(給header傳遞模型)
  header.group = self.groups[section];
  return header;
}

+ (instancetype)headerViewWithTableView:(UITableView *)tableView
{
  static NSString *ID = @"header";
  HeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:ID];
  if (header == nil) {
    header = [[HeaderView alloc] initWithReuseIdentifier:ID];
  }
  return header;
}

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier//在這個初始化方法中,HeaderView的frame\bounds沒有值
{
  if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
    // 添加子控制項
    nameView.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//設定按鈕的內容靠左對齊
    nameView.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);// 設定按鈕的內邊距
    nameView.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [nameView addTarget:self action:@selector(nameViewClick) forControlEvents:UIControlEventTouchUpInside];
    nameView.imageView.contentMode = UIViewContentModeCenter;// 設定按鈕內部的imageView的內容模式為置中
    nameView.imageView.clipsToBounds = NO;// 超出邊框的內容不需要裁剪
  }
  return self;
}

- (void)layoutSubviews//當一個控制項的frame發生改變的時候就會調用,一般在這裡布局內部的子控制項(設定子控制項的frame)
{
  [super layoutSubviews];//一定要調用super的方法
  // 1.設定按鈕的frame
  self.nameView.frame = self.bounds;
  // 2.設定好友數的frame
  CGFloat countY = 0;
  CGFloat countH = self.frame.size.height;
  CGFloat countW = 150;
  CGFloat countX = self.frame.size.width - 10 - countW;
  self.countView.frame = CGRectMake(countX, countY, countW, countH);
}

- (void)didMoveToSuperview//當一個控制項被添加到父控制項中就會調用
{
  if (self.group.opened) {
    self.nameView.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);
  } else {
    self.nameView.imageView.transform = CGAffineTransformMakeRotation(0);
  }
}

- (void)willMoveToSuperview:(UIView *)newSuperview//當一個控制項即將被添加到父控制項中會調用
{ }

 


35.Info.plist常見的設定
建立一個工程後,會在Supporting files檔案夾下看到一個“工程名-Info.plist”的檔案,該檔案對工程做一些運行期的配置,非常重要,不能刪除
在舊版本Xcode建立的工程中,這個設定檔的名字就叫“Info.plist”
項目中其他Plist檔案不能帶有“Info”這個字眼,不然會被錯認為是傳說中非常重要的“Info.plist”
項目中還有一個InfoPlist.strings的檔案,跟Info.plist檔案的本地化相關
常見屬性
Localiztion native development region(CFBundleDevelopmentRegion)-本地化相關
Bundle display name(CFBundleDisplayName)-程式安裝後顯示的名稱,限制在10-12個字元,如果超出,將被顯示縮寫名稱
Icon file(CFBundleIconFile)-app表徵圖名稱,一般為Icon.png
Bundle version(CFBundleVersion)-應用程式的版本號碼,每次往App Store上發布一個新版本時,需要增加這個版本號碼
Main storyboard file base name(NSMainStoryboardFile)-主storyboard檔案的名稱
Bundle identifier(CFBundleIdentifier)-項目的唯一標識,部署到真機時用到

 

36.PHC檔案
項目的Supporting files檔案夾下面有個“工程名-Prefix.pch”檔案,也是一個標頭檔
pch標頭檔的內容能被項目中的其他所有源檔案分享權限設定和訪問
一般在pch檔案中定義一些全域的宏
在pch檔案中添加下列預先處理指令,然後在項目中使用Log(…)來輸出日誌資訊,就可以在發布應用的時候,一次性將NSLog語句移除(在偵錯模式下,才有定義DEBUG)
#ifdef DEBUG
#define Log(...) NSLog(__VA_ARGS__)
#else
#define Log(...) /* */
#endif

 

37.UIApplication
UIApplication對象是應用程式的象徵
每一個應用都有自己的UIApplication對象,而且是單例的
通過[UIApplication sharedApplication]可以獲得這個單例對象
一個iOS程式啟動後建立的第一個對象就是UIApplication對象
利用UIApplication對象,能進行一些應用層級的操作

 

38.UIApplication的常用屬性
@property(nonatomic) NSInteger applicationIconBadgeNumber;//設定應用程式圖示右上方的紅色提醒數字
@property(nonatomic,getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;//設定連網指標的可見度

 

39.iOS7中的狀態列
從iOS7開始,系統提供了2種管理狀態列的方式
1.通過UIViewController管理(每一個UIViewController都可以擁有自己不同的狀態列)
2.通過UIApplication管理(一個應用程式的狀態列都由它統一管理)
在iOS7中,預設情況下,狀態列都是由UIViewController管理的,UIViewController實現下列方法就可以輕鬆管理狀態列的可見度和樣式
- (UIStatusBarStyle)preferredStatusBarStyle; //狀態列的樣式
- (BOOL)prefersStatusBarHidden; //狀態列的可見度

 

40.openURL
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"tel://10086"]];//打電話
[app openURL:[NSURL URLWithString:@"sms://10086"]];//發簡訊
[app openURL:[NSURL URLWithString:@"mailto://[email protected]"]];//發郵件
[app openURL:[NSURL URLWithString:@"http://ios.itcast.cn"]];//開啟一個網頁資源

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.