Передача данных из ячейки прототипа с помощью кнопки внутри ячейки таблицы

Если вы не хотите получать глубокую копию памяти каждый раз, когда вам нужна подпоследовательность, вы можете использовать кубики

. Но имейте в виду, что весь фоновый массив будет в памяти, если у вас есть хотя бы одна ссылка на срез.

Например:

ByteBuffer buff = ByteBuffer.allocate(128);
buff.order(ByteOrder.nativeOrder());
for(int i=0; i < 128; i++) {
    buff.put((byte)i);
}

// use custom code instead of flip, to provide a slice
buff.position( 32 );
buff.limit(64);

ByteBuffer subBuffer = buff.slice();

// custom flip
buff.limit(128);
buff.position(0);

System.out.print("Sub buffer: [");
for(int i=0; i < subBuffer.limit(); i++) {
    System.out.print( String.format(" %d,", subBuffer.get(i) ) );
}
System.out.println(" ]");

System.out.print("Whole buffer: [");
for(int i=0; i < buff.limit(); i++) {
    System.out.print( String.format(" %d,", buff.get(i) ) );
}
System.out.println(" ]");

Выходы:

Sub buffer: [ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, ]
Whole buffer: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, ]

0
задан Julian Silvestri 19 January 2019 в 16:43
поделиться

1 ответ

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "part", for: indexPath) as! partsTableCell

let part = partList[0]

cell.a.text = String(part.a)
cell.b.text = part.b
cell.c.text = part.c
cell.d.text = part.d
cell.e.text = part.e
cell.f.text = part.f

self.tableView.rowHeight = 250
cell.layer.borderColor = UIColor.darkGray.cgColor
cell.layer.borderWidth = 1
cell.layer.cornerRadius = 5
cell.clipsToBounds = true

// give tag to your button and add target
cell.myButton.tag = indexPath.row
cell.myButton.addTarget(self, action: #selector(myButtonAction), for: .touchUpInside)

return cell

}

@objc func myButtonAction(sender:UIButton)  {
// in button action do your stuff like below

let part = partList[sender.tag]

let detailVC = UIStoryboard(name: "YourStoryBoard", bundle: nil).instantiateViewController(withIdentifier: "partDetail") as! PartsVCDetail
detailVC?.a = part.a!
detailVC?.b = part.b!
detailVC?.c = part.c!
detailVC?.d = part.d!
detailVC?.e = part.e!
detailVC?.f = part.f
self.navigationController?.pushViewController(detailVC, animated: true)

}

0
ответ дан Yogita J 19 January 2019 в 16:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: