Tag Archives: iOS

Creative & Tech

Custom UITableViewCell without Storyboard

I was looking for the way to make List function based on UITableView be directly editable text field. UITableView also offer editable by swipe function. But I wanted to make function to directly edit lists on UITableView. To make sure that, Custom UITableViewCell is needed, if without StoryBoard. Btw I prefer to generate content without using StoryBoard, it means my application completely depends on source code. 

Step 1: To make new class “CustomTableViewCell” by inheriting “UITableViewCell”.

class CustomTableViewCell: UITableViewCell{
    
    let TitleArea: UITextField = UITextField(frame: CGRect(x: 30, y: 5, width: 350, height: 25))
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String!)
    {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        TitleArea.delegate = self
        contentView.addSubview(TitleArea)
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    
    required init(coder aDecoder: NSCoder)
    {
        super.init(coder: aDecoder)!
    }    
}

and to implement this custom class without StoryBoard, most important thing is to define it on “TableView.registerClass” and “return value of UITableViewCell. Please refer below highlited line in sample source code.

class CustomViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    var CusotmTableView: UITableView = UITableView()
	
    override func viewDidLoad() {
        super.viewDidLoad()
            
        // Get width and height of view.
        let displayWidth: CGFloat = self.view.frame.width
        let displayHeight: CGFloat = self.view.frame.height
        
        // Generate TableView
        CusotmTableView.frame = CGRect(x: 0, y: barHeight+30, width: displayWidth, height: displayHeight  )
        
        // [Important] To designate Custom UITableViewcells as UITableViewCell
        CusotmTableView.registerClass(CustomTableViewCell.self, forCellReuseIdentifier: "MyCell")
        
	CusotmTableView.dataSource = self
        CusotmTableView.delegate = self
        
        self.view.addSubview(CusotmTableView)
        

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }
	
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return ******
    }
    
    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return "title"
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return section
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        //CustomCell
        let cell:  CustomTableViewCell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) as! CustomTableCell
        cell.delegate = self
        
        return cell
    }
   
}

If you want to generate Custom UITableViewCell by source code without StoryBorder, Please make sure these two points. 

Creative & Tech

SubThread for UIView Control

I’m continually developing original reminder’s app. I faced one issue when showing content on view. After got reminder’s data from EventStore, tried to put it as UITextView to confirm what kind reminders we can retrieve. But UITextView has error with following message.

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

This was caused by multi thread processing. Some process to display reminder text into UITextFiled after get reminder data was contained in closure of function to retrieve reminder data from EventStore with identifier. Those process was called per identifier, it means in case of multi reminder list which the device has. Then each processes to modify UITextField were in subthread.  

As solution for this, I implemented “Dispatch_sync” method by referring to Grand Central Dispatch (GCD) Reference

dispatch_sync(dispatch_get_main_queue(),
            {
                self.textfiled.text = "Sample text to show text from subthread."
            })

It was success without any error. I could learn one new thing for iOS at this time.

Creative & Tech

EKSource

This is my note about iOS Application development which is originally managing event data ( Calendar or Reminder) to make sure be more easy UI for me.

To get Calendar or Reminder List from iOS device, EKEventStore class is basement to access to those database. And in that data base there are some datasource. EKSource class contains data source definition like “iCloud”, “Default”, 

EKSource.title(String) SourceType Memo
Default Local  
Other ??  
Subscribed Calendar Subscribed  
iCloud CalDAV  

These definition might work for permission to read & write the event. I will keep to investigate it.

 

 

Creative & Tech

Good reference for beginner of iOS App developer

From beginning of this year, I have been planning to develop iOS App to learn Swift and Xcode development. As fast step, started with learning some UI design concept for iOS and making mock. There are many document or guideline offered by Apple.  And Adobe provides many tool to make mock for Smartphone Apple. 

I would like to recommend some documents and services for the beginner of developer like me. and if i will find more good one, let me update here or post new one.

Site Title Memo
Apple iOS Human Interface Guidelines. Basic Document
Apple WWDC Video Official and biggest MacOSX and iOS developer conference by Apple.
Adobe Adobe Comp Mock Application for not only for SmartDevice, also Web & Publishing. Easy to share the mock with Desktop Adobe Creative Suite like Photoshop and Illustrator.  
A Map of the Unexplored Project iOS Fonts Available Font list on iOS Application.
Creative & Tech

UIkit on Cocoa

Continually studying iOS App development by referring some document and online website. just getting used to Xcode Interface. But there are some many framework function based on Cocoa. I have not yet looked over all UIKit framework. I have some idea for the app. trying to find best way to build UI based on some UIkit module. will look for UIKit list to make me be easy to find the best one.

UIKit User Interface Catalog

20151117