jeudi 25 juin 2015

How to add button to UITableViewController in static cells?

I have a UITableViewController,and have set its content to Static Cells,style to grouped. My question is how to add the red button to the tableview appropriately,Any ideas?

enter image description here

See more ..

custom table cell displaying nil

I'm trying to set the title and display a button in my custom cell object in my second table view controller, but only my first dynamic prototype cell is displaying text.

The first prototype cell is UITableViewCell and the second is the custom object. In my first view controller I implement almost the same exact method and it works completely fine. Not sure where my error could be, the models I use have all their data in them. I have the correct cell identifier in my storyboard, and the connection from custom cell to the UIButton is set.

Thanks in advance.


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CellIdentifier";
    static NSString *QuestionSectionIdentifier = @"QuestionSectionCell";

    if (indexPath.section == 0) {
        UITableViewCell *cellQuestion = [tableView dequeueReusableCellWithIdentifier:QuestionSectionIdentifier];
        if (cellQuestion == nil) {
            cellQuestion = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:QuestionSectionIdentifier];
        if (indexPath.row == 0) {
            cellQuestion.textLabel.text = _headerQuestion.question;
            NSLog(@"question here %@", cellQuestion.textLabel.text);

        return cellQuestion;

    else {
        MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        if (indexPath.section == 1) {

            if (indexPath.row == 0) {
                [cell.firstButton setTitle:_headerQuestion.questionAuthor.fullName forState:UIControlStateNormal];
                [cell.firstButton setTag:_headerQuestion.questionAuthor.userID];
                [cell.answerLabelField setHidden:YES];

                NSLog(@"section 1  %@", cell.firstButton.titleLabel.text);



        else  if (indexPath.section == 2) {
                Answer* answer_num =  [_headerQuestion.answers objectAtIndex:indexPath.row]; //object at index
                [cell.firstButton setTitle:answer_num.answerAuthor.fullName forState:UIControlStateNormal];
                [cell.firstButton setTag:answer_num.answerAuthor.userID];
                cell.answerLabelField.text = answer_num.answer;

        return cell;


See more ..

UITableViewCell subclass IBOutlets returns nil

I've set up an UITableViewCell subclass from storyboard and connected the subviews as IBOutlets, as you can check here:

public class WaitingStatusTableViewCell: UITableViewCell {

@IBOutlet weak var leftBoxView: UIView!
@IBOutlet weak var leftTimeLabel: UILabel!
@IBOutlet weak var leftTitleLabel: UILabel!

Overrided the initialisers:

 override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)

required public init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

And on the initialConfigure function I try to configure some properties of my subviews

    func initialConfigure() {
    self.leftBoxView.backgroundColor = UIColor.clearColor()
    self.leftBoxView.layer.shadowColor = UIColor.darkGrayColor().CGColor
    self.leftBoxView.layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: 12.0).CGPath
    self.leftBoxView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
    self.leftBoxView.layer.shadowOpacity = 1.0
    self.leftBoxView.layer.shadowRadius = 2
    self.leftBoxView.layer.masksToBounds = true
    self.leftBoxView.clipsToBounds = false

It doesn't work at all, I receive the following error:

fatal error: unexpectedly found nil while unwrapping an Optional value

Any ideas?

Oh, by the way, it works on drawsRect function, but I really want to understand the "why"

See more ..

Predicates and combined filters in core data?

I'm not using Core Data currently, but I'm about to switch to it from Realm, if I'm sure a certain thing will work, which is vital to the way my application currently works. I have a model with two objects:

date - NSDate
text - String
images - One-to-many > Image

imageURL - String
message - Many-to-one > Image

I have a table view which displays both Images and Messages. I need to know what should go at a certain index path, for when UITableView wants to know. So I need to be able to perform a query akin to:

"Give me an ordered list of images and messages, messages sorted by their date and images sorted by their".

How could I do this?

See more ..

Why UIRefreshControl jumping?

I try to use the UIRefreshControl with swift 1.2 and works fine except the UI. It is jumping and I dont know why. Here is what I am doing:

class ViewController: UIViewController {

     var refreshControl:UIRefreshControl!

    @IBOutlet weak var tableView: UITableView!
    override func viewDidLoad() {

        self.refreshControl = UIRefreshControl()
        self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
        self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)

    func refresh(sender:AnyObject) {
        // Code to refresh table view


And you can download my poc project from here: POC project

While you pull down the tableView, suddenly jump a little bit down. Has anybody any idea why?

If I use with UITableViewController, It works fine but I dont want to use this UI object. I would like to use a simple UITableView in a UIViewController.

See more ..

Position a view with myView.frame

I have done a simple code:

myView.frame = CGRectMake(0, 0, 150, 150) 

in viewDidLoad and it is working well as expected.

But after I link this view from a table view and embed it into a navigation controller, it doesn't work.

Did I miss something?

See more ..

Cell reuse beginner? Tapping button in one cell affects another

I have a TableViewController with a custom cell. When I tap the like button inside one of the cells, it is causing at least one other cell to have the like button tapped.

I am using Parse, and it is not affecting the actual like count of the second one which is being ghost tapped, but it is disabling the like button and turning it red.

I have read about cell reuse, and similar topics but am completely lost. I am new to swift, and if someone could help me navigate how to fix this, I can't find a solution on SO about Swift, and Parse.


 @IBAction func likeButtonTapped(sender: AnyObject) {

    let chinTwo = self.timelineData[sender.tag] as! PFObject

    chinTwo["likeCount"] = (chinTwo["likeCount"] as! Int) + 1

    sender.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)

    chinTwo.saveInBackgroundWithBlock {
        (success: Bool, error: NSError?) -> Void in
        if (success) {
        } else {
            println("Didn't Work")




@IBAction func likeTapped(sender: AnyObject) { 
    likeButton.enabled = false

The same problem occurs with the report button.

See more ..