極客班iOS應(yīng)用開發(fā)實(shí)戰(zhàn)測(cè)試題二:同學(xué)錄

極客班iOS應(yīng)用開發(fā)實(shí)戰(zhàn)測(cè)試題二(8月31日)

習(xí)題:同學(xué)錄

項(xiàng)目源碼見 GitHub

1. 題目要求:

  • 實(shí)現(xiàn)一個(gè)同學(xué)錄列表,包含姓名、簡(jiǎn)介和頭像等信息。
  • 可以添加新的同學(xué),支持拍照添加頭像。
  • 可以查看每一個(gè)的同學(xué)詳情頁(yè)。
  • 實(shí)現(xiàn)存儲(chǔ)所有同學(xué)的信息。
Classmates
Classmates

2. 實(shí)際開發(fā)遇到的點(diǎn):

// Updating Objects with primary keys
// This will make properties no settled be NULL
[GWClassmate createOrUpdateInDefaultRealmWithValue:newClassmate];
  • 兩種編輯保存界面: 微信進(jìn)入編輯的界面,Back 有個(gè)Alert確認(rèn)保存; Phone.app 則是禁用右滑和 Back,顯示 Cancel & Done,也是完善的方案。


    Edit View
    Edit View
  • Estimating default values for properties of Classmate

    • In Domain Logic: ClassmateDB.h/m (BEST Solution)
    • In Model: Classmate.h/m, Specify default values. BUT Realm isn't support nil property.
    • In View Controller: if/esle
    • In Interface Builder: Setting a default value. Especially giving a default avatar is a nice solution for user.

    RLMPropertyType Constants Reference

  • "To use AVAsset to extract metadata informations, this post is useful." http://stackoverflow.com/questions/16318821/extracting-mp3-album-artwork-in-ios

  • Playing video in iOS

3.項(xiàng)目完成情況:

完成1.0:

  • 基本功能完成
  • 列表使用了縮略圖,待優(yōu)化直接保存數(shù)據(jù)庫(kù)
  • 輸入鍵盤時(shí),View 自動(dòng)升降一個(gè)鍵盤高度,以保持可見
  • 保存是檢驗(yàn)用戶名,不能為空
  • 使用 Realm 數(shù)據(jù)庫(kù)
  • classmate.h/m 為 Model,四個(gè)屬性分別為:uuid、name、info & avator
  • Using GWDetailViewController as super class to GWShowDetailViewController can easy to create a new view.

2015-08-31 20:17:00

完成1.1:

  • 使用 FMDB

把習(xí)題同學(xué)錄的存儲(chǔ) Realm 換成 FMDB,午飯到16:00還沒(méi)吃,我的學(xué)習(xí)新的知識(shí)的能力還比較低的。需要投入更多時(shí)間來(lái)學(xué)習(xí)了。

2015-09-01 16:09:00

完成1.2:

  • 換回 Realm
  • 增加編輯和刪除功能

2015-09-01 20:00:00

完成1.3:

  • 隨機(jī)添加修改和刪除10000個(gè)classmate,以測(cè)試性能
  • Add a tab bar view as root view
  • UI layout like Wechat
  • Set UUID as parimary key
  • Updating Objects With Primary Keys
  • 把取消按鈕改為 Button,并把 Segue to GWDetailViewController & GWShowDetailViewController, 改為 Modle
  • New a manaager class: GWClassmateDB, to abstract most useful SUQD methods and testing methods.

2015-09-02 18:20:47

完成1.4:

  • Change cell's Accessory form Detail to Disclosure Indicator
  • Specify default values for properties of Classmate.h/m
  • Add Music Tab
  • Add a "red dot badge" on avatars' view for test.
  • Change the classmates display style. Just looks like WeChat.app.

2015-09-06 11:43:19

Classmates v1.4
Classmates v1.4

進(jìn)行中1.5:

  • Adapting to MVVM
  • XCTest
  • Add a 'Edit' Button, and after taped the 'back' button in navigation change to "cancel", add a "Done" in right. Just looks like Phone.app.
  • Add Sort by name, and index by initial
  • Add Search

4. BUG

以下的代碼提示越界錯(cuò)誤:Terminating app due to uncaught exception 'RLMException', reason: 'Index is out of bounds.'可能的原因:

需要注意的是,寫入操作會(huì)相互阻塞,而且其相對(duì)應(yīng)的進(jìn)程也會(huì)受到影響。這和其他的永久數(shù)據(jù)存儲(chǔ)解決方案是一樣的,所以我們建議你使用常用的,也是最有效的方案, 將所有寫入放到一個(gè)單獨(dú)的進(jìn)程中。https://realm.io/cn/docs/objc/latest/

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showDetail"]) {
        
        NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
        GWCustomTableViewCell *cell = (GWCustomTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
        
        GWDetailViewController *vc = (GWDetailViewController *)segue.destinationViewController;
        
//        vc.userid       = cell.userid;
        vc.name.text    = cell.name.text;

    }
}

最終解決方法是修改 Custom Cell 中添加一個(gè) UILabel 的 text 來(lái)存儲(chǔ) UUID,并設(shè)置為隱藏。并添加使用 Detail Disclosure 測(cè)試 NSLog UUID。具體的越界問(wèn)題,還需要在研究。

5. Further Reading

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容