我正在使用Xamarin开发一个小型测试iOS应用程序,它显示一个填充了推文的TableView。我有一个简化版帐户,所以我避免使用组件,因为这些增加了我的二进制文件的大小。Xamarin UITableView不会滚动
我有一个TableViewController并用足够的数据填充UITableView来生成滚动,但它不会滚动。
我已经在故事板上将Scroll Enabled设置为true,我的TableSource类有一个包含要显示的数据的List。每个单元格(我使用的单元格样式都是UITableViewCellStyle.Value1)在UITableView中显示tweet文本,发布它的人,创建日期和用户图像。
我TableSource类的结构是这样的:
public class TableSource : UITableViewSource
{
List<Tweet> tableItems;
public static string cellIdentifier = "TableCell";
public Dictionary<string, UIImage> photoCache;
public TableSource (List<Tweet> items)
{
tableItems = items;
photoCache = new Dictionary<string, UIImage>();
}
public override int RowsInSection(UITableView tableview, int section){
return tableItems.Count;
}
public override UITableViewCell GetCell(UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath){
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
if (cell != null) {
cell = new UITableViewCell (UITableViewCellStyle.Value1, cellIdentifier);
}
var index = indexPath.Row;
var tweet = tableItems [index];
cell.TextLabel.Text = tweet.TweetText;
cell.DetailTextLabel.Text = "by " + tweet.UserName + " at " + tweet.CreatedAt.ToShortDateString();
if (!photoCache.ContainsKey(tweet.UserImage)) {
using (var imgUrl = new NSUrl (tweet.UserImage)) {
using (var data = NSData.FromUrl (imgUrl)) {
var img = UIImage.LoadFromData (data);
cell.ImageView.Image = img;
photoCache.Add (tweet.UserImage, img);
}
}
} else {
cell.ImageView.Image = photoCache [tweet.UserImage];
}
return cell;
}
}
正如你可以看到我有保存资料Tweet对象列表(鸣叫具有文本,用户名,DateTime对象和用户图像URL),还我有一个词典来保存下载的用户照片。单元格创建时没有问题,并且看起来应该如此。
但UITableView不会滚动。
它解析鸣叫和创建的UITableView的光源的方法是这样的:
private void ReadStreamFromTwitterMentionsResponse(WebResponse response){
using (Stream responseStream = response.GetResponseStream()) {
using (StreamReader sr = new StreamReader (responseStream)) {
// read response and parse it
string content = sr.ReadToEnd();
var json = JsonObject.Parse (content);
var statuses = json ["statuses"];
// for each status create a Tweet object and put it in a List
foreach (JsonObject status in statuses) {
try{
var user_name = status ["user"] ["name"];
var user_image = status ["user"] ["profile_image_url"];
var tweet_text = status ["text"];
var tweet_date = status ["created_at"];
Console.WriteLine("tweet_date " + tweet_date);
DateTime tweet_date_obj = DateTime.ParseExact (tweet_date, "ddd MMM dd HH:mm:ss zzzz yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal);
tweets.Add(new Tweet(tweet_text, user_name, user_image, tweet_date_obj));
}catch(Exception ex){
Console.WriteLine ("Error " + ex.Message);
}
}
// After finishing filling the List with tweets, tell main thread to
// make a TableSource instance and pass the tweets list and to reload its data
InvokeOnMainThread (delegate {
TableView.Source = new TableSource (tweets);
TableView.ReloadData();
// The following line returns a Rectangle which height value is greater than the device's height
Console.WriteLine("content size " + TableView.ContentSize);
});
}
}
}
我遇到了类似的问题来到CollectionViews,控制里面的内容就足以挑起滚动而滚动ISN” t触发。
我错过了什么吗?为什么不滚动内容?
编辑1
为了确保UITableView中确实有细胞外可见帧我叫ScrollRectToVisible方法和滚动到指定区域的UITableView,编程我可以滚动,但UITableView的是忽略了用户触摸手势。
我必须指定一个触摸手势来启用滚动吗?当我点击一行时,它会被选中,所以只有滚动没有响应?
编辑2
忘了澄清一些,所述的UITableView是通过与一个TableViewController故事板生成。
这是我第一次遇到这种类型的错误,甚至是本机的,或者是Titanium SDK,我都没有遇到过这种错误。我想这是由于Xamarin。 – 2014-09-30 21:36:33