1

Hi would like to create custom tableViewCell with hyperloop. The problem is, I don't figure how to. I've tried implement it with a swift class :

Cell.swift

import UIKit

public class MyCell: UITableViewCell{//UICollectionViewCell {

    public var imgUser:UIImageView = UIImageView()
    public var labUerName:UILabel = UILabel()
    public var labMessage:UILabel = UILabel()
    public var labTime:UILabel = UILabel()

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        NSLog("la");
        imgUser.backgroundColor = UIColor.blue

        imgUser.translatesAutoresizingMaskIntoConstraints = false
        labUerName.translatesAutoresizingMaskIntoConstraints = false
        labMessage.translatesAutoresizingMaskIntoConstraints = false
        labTime.translatesAutoresizingMaskIntoConstraints = false

        labUerName.frame = CGRect(x: 5, y: 5, width: 70, height: 30)

        contentView.addSubview(imgUser)
        contentView.addSubview(labUerName)
        contentView.addSubview(labMessage)
        contentView.addSubview(labTime)


    }

    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    public func setName(txt: String){
        labUerName.text = txt
    }


}

In my tabbleview controller:

(function (container) {

    var UIScreen = require('UIKit/UIScreen'),
        UIColor = require('UIKit/UIColor'),
        UITableView = require('UIKit/UITableView'),
        UITableViewCell = require('UIKit/UITableViewCell'),
        NSIndexPath = require('Foundation').NSIndexPath,
        UITableViewStyleGrouped = require('UIKit').UITableViewStyleGrouped,
        UITableViewCellStyleSubtitle = require('UIKit').UITableViewCellStyleSubtitle,
        UITableViewCellAccessoryDisclosureIndicator = require('UIKit').UITableViewCellAccessoryDisclosureIndicator;

    // Grabs the JSON-file from app/lib/static/data.json 
    var file = Ti.Filesystem.getFile(Ti.Filesystem.getResourcesDirectory() + 'static/data.json'); 
    var users = JSON.parse(file.read().text).users;
    var Cell = require('MyFramework/MyCell'); // HERE IS MY CUSTOM CELL

    // Subclass delegate + data source
    var TableViewDataSourceAndDelegate = require('subclasses/tableviewdatasourcedelegate');

    // Create + configure tableView
    var tableView = UITableView.alloc().initWithFrameStyle(UIScreen.mainScreen.bounds, UITableViewStyleGrouped);
    var dataSourceDelegate = new TableViewDataSourceAndDelegate();

    dataSourceDelegate.numberOfSections = function(tableView) {
        return 1;
    };
    dataSourceDelegate.numberOfRows = function(tableView, section) {
        return users.length;
    };
    dataSourceDelegate.titleForHeader = function(tableView, section) {
        return 'Available users: ' + users.length;
    };
    dataSourceDelegate.heightForRow = function(tableView, indexPath) {
        return 44;
    };
    dataSourceDelegate.cellForRow = function(tableView, indexPath) {

        var user = users[indexPath.row];


        var cell = tableView.dequeueReusableCellWithIdentifierForIndexPath('hyperloop_cell', indexPath);



        cell.setName('abc');

        return cell;
    };
    dataSourceDelegate.didSelectRowAtIndexPath = function(tableView, indexPath) {       
        alert('Call me maybe: ' + users[indexPath.row].phone);
        tableView.deselectRowAtIndexPathAnimated(indexPath, true);
    };


    // Assign delegate + data source
    tableView.registerClassForCellReuseIdentifier(Cell.self, "hyperloop_cell");
    tableView.setDelegate(dataSourceDelegate);
    tableView.setDataSource(dataSourceDelegate);

    container.add(tableView);

})($.tableview_container);

i don't know how to use it well. Can someone help me please ? thanks

Maxime Girou
  • 1,511
  • 2
  • 16
  • 32

1 Answers1

0

Not sure why it's not working, however it doesn't seem like you're doing anything that could not be done without hyperloop... Why not just create your own tableview cell/row layout with Appcelerator?

Ray
  • 486
  • 2
  • 4
  • I've tried to make it in JS. i didn't figure it how to do it. That's why i've tried with swift. – Maxime Girou Jul 11 '17 at 10:00
  • Seems like it should be capable, so maybe you just need to brush up on the documentation? Or maybe post what you want the row to look like and maybe can help pointing you in the right direction. – Ray Jul 11 '17 at 15:12
  • After many tries, the problem seem's to be my swift class. I empty all the stuff in it and it work's as normal... i'll continue to search in that way – Maxime Girou Jul 12 '17 at 08:37