Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static NSString* reuseIdentifier = @"Cell";
- UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
- if(!cell)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
- }
- tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "Cell")
- let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
- var cell :UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
- var cell:UITableViewCell? =
- tableView?.dequeueReusableCellWithIdentifier(reuseIdentifier) as? UITableViewCell
- if (cell == nil)
- {
- cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
- reuseIdentifier: reuseIdentifier)
- }
- // At this point, we definitely have a cell -- either dequeued or newly created,
- // so let's force unwrap the optional into a UITableViewCell
- cell!.detailTextLabel.text = "some text"
- return cell
- let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) ?? UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
- cell.detailTextLabel?.text = "some text"
- return cell
- let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) ?? UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
- cell.detailTextLabel?.text = ""
- return cell
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell: UITableViewCell = {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell") else {
- // Never fails:
- return UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "UITableViewCell")
- }
- return cell
- }()
- // (cell is non-optional; no need to use ?. or !)
- // Configure your cell:
- cell.textLabel?.text = "Key"
- cell.detailTextLabel?.text = "Value"
- return cell
- }
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let reuseIdentifier = "cell"
- var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as UITableViewCell?
- if (cell == nil) {
- cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
- }
- cell!.textLabel?.text = self.items[indexPath.row]
- cell!.detailTextLabel?.text = self.items[indexPath.row]
- return cell!
- }
- let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as? UITableViewCell ?? UITableViewCell(style: .Subtitle,
- reuseIdentifier: reuseIdentifier)
- cell.detailTextLabel?.text = "some text"
- return cell
- func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
- {
- let cell = tableView .dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
- cell.textLabel.text = String(format: "%i", indexPath.row+1)
- // set any other property of your cell here
- return cell
- }
- if !cell { .....
- if cell == nil { ...
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:
- NSIndexPath) -> UITableViewCell {
- var CellIdentifier:String = "Cell"
- var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(CellIdentifier) as? UITableViewCell
- if cell == nil {
- cell = UITableViewCell(style:UITableViewCellStyle(rawValue:3)!,reuseIdentifier:CellIdentifier)
- }
- return cell!
- }
- override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: cellId)
- let user = users[indexPath.row]
- cell.textLabel?.text = user.name
- cell.detailTextLabel?.text = user.email
- return cell
- }
- var cell = tableView.dequeueReusableCell(withIdentifier: yourCellReuseIdentifier, for: indexPath)
- if cell.detailTextLabel == nil {
- cell = UITableViewCell(style: .value1, reuseIdentifier: repeatCellReuseIdentifier)
- }
- cell.textLabel?.text = "Title"
- cell.detailTextLabel?.text = "Detail"
- return cell
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
- {
- var cell:UITableViewCell? =
- tableView.dequeueReusableCell(withIdentifier: "cell")
- if (cell != nil)
- {
- cell = UITableViewCell(style: UITableViewCellStyle.subtitle,
- reuseIdentifier: "cell")
- }
- cell!.textLabel?.text = "ABC"
- cell!.detailTextLabel?.text = "XYZ"
- return cell!
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "My Reuse Identifier", for: indexPath)
- cell.textLabel?.text = "Key"
- cell.detailTextLabel?.text = "Value"
- return cell
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement