如何UITableViewCell在表格视图中使用s 内的自动布局,让每个单元格的内容和子视图确定行高(本身/自动),同时保持平滑的滚动性能?
我正在阅读AsyncTask,我尝试了下面的简单程序.但它似乎没有用.我怎样才能使它工作?
public class AsyncTaskActivity extends Activity {
Button btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener((OnClickListener) this);
}
public void onClick(View view){
new LongOperation().execute("");
}
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
for(int i=0;i<5;i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
TextView txt = (TextView) findViewById(R.id.output); …Run Code Online (Sandbox Code Playgroud) 如何在滑动时显示删除按钮UITableViewCell?永远不会引发该事件,并且永远不会出现删除按钮.
自上周以来我一直试图解决这个问题,而没有更进一步.好的,所以我需要在Swift中以编程方式应用一些约束 来使用这段代码:UIView
var new_view:UIView! = UIView(frame: CGRectMake(0, 0, 100, 100));
new_view.backgroundColor = UIColor.redColor();
view.addSubview(new_view);
var constX:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0);
self.view.addConstraint(constX);
var constY:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0);
self.view.addConstraint(constY);
var constW:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: new_view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0);
self.view.addConstraint(constW);
var constH:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: …Run Code Online (Sandbox Code Playgroud) 我正在努力学习如何使用UICollectionView.该文件是一个有点难以理解,而我发现教程无论是在目标C或长期复杂的项目当中.
当我学习如何使用时UITableView,我们❤Swift的 如何用iOS 8和Swift制作一个简单的桌面视图有一个非常基本的设置和解释让我去.有这样的东西UICollectionView吗?
下面的答案是我试图学习如何做到这一点.
有没有办法增加间距UITableViewCell?
我创建了一个表,每个单元格只包含一个图像.图像被分配给单元格,如下所示:
cell.imageView.image = [myImages objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)
但这会使图像放大并适合整个单元格,图像之间没有间距.
或者以这种方式说,图像的高度例如是50,并且我想在图像之间添加20个间隔.有没有办法实现这个目标?
我在表格视图中有一个效果列表.我创建了一个右上角的条形按钮,它可以将push segue推送到另一个视图控制器,这有助于创建一个新的效果.现在我想将push segues添加到表格视图单元格中,以便可以在添加效果视图控制器上加载效果值,我可以保存已编辑的值.
问题是我可以通过编程方式创建push segue吗?如果没有,我可以通过一个prepareforsegue?如果我尝试使用一个prepareforsegue,我遇到一个问题,控制拖动从UITableView不让我创建推送segue到添加效果视图控制器.
我有一个带有几个IBOutlets的自定义单元类.我已将该课程添加到故事板中.我连接了所有的插座.我的cellForRowAtIndexPath函数如下所示:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as SwipeableCell
cell.mainTextLabel.text = self.venueService.mainCategoriesArray()[indexPath.row]
return cell
}
Run Code Online (Sandbox Code Playgroud)
这是我的自定义单元类:
class SwipeableCell: UITableViewCell {
@IBOutlet var option1: UIButton
@IBOutlet var option2: UIButton
@IBOutlet var topLayerView : UIView
@IBOutlet var mainTextLabel : UILabel
@IBOutlet var categoryIcon : UIImageView
init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我的所有单元格都是空的.我已经注销self.venueService.mainCategoriesArray(),它包含所有正确的字符串.我也试过把一个实际的字符串等于标签,这会产生相同的结果.
我错过了什么?任何帮助表示赞赏.
我有一个连接到某些项目的标签栏视图。
我希望这些项目之一包含TableView,但我不想使用TableViewController因为我想在页面顶部添加其他内容。
My ViewController实现了2个协议UITableViewDataSource,UITableViewDelegate并包含以下功能:
func tableView(_ tableView: UITableView, numberOfRowsInSection
section: Int) ->
Int {
// Return the number of rows in the section.
return annunci.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) ->
UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier:
cellIdentifier, for: indexPath)
// Configure the cell...
cell.textLabel?.text = annunci[indexPath.row]
return cell }
Run Code Online (Sandbox Code Playgroud)
然后,从情节提要中添加了一个标识符为“ Cell”的原型单元,并将其链接tableView到viewController as的DataSource和Delegate。
当我运行该应用程序时,可以,但是,当我选择包含表视图的项目时,该应用程序将抛出此异常:
*** Terminating app due to uncaught exception …Run Code Online (Sandbox Code Playgroud) ios ×7
uitableview ×6
swift ×4
objective-c ×3
autolayout ×2
cocoa-touch ×2
android ×1
ios8 ×1
nsautolayout ×1
row-height ×1
segue ×1
storyboard ×1
uikit ×1
uiview ×1